11.10. Python Reporting Cheat Sheet#

import polars as pl
from datascipsych import datasets
data = pl.read_csv(datasets.get_dataset_file("Onton2005"))

Summary statistics#

When examining how some dependent variable varies with changes in an independent variable, it is a good idea to calculate summary statistics for each value of the independent variable.

First, calculate the mean of the dependent variable for each subject and each value of the independent variable.

mean_rt_probe = (
    data.group_by("subject", "probe")
    .agg(pl.col("response_time").mean())
    .sort("subject", "probe")
)
mean_rt_probe.head(6)
shape: (6, 3)
subjectproberesponse_time
i64strf64
1"lure"0.952467
1"target"0.850602
2"lure"1.02368
2"target"0.847816
3"lure"1.828131
3"target"1.251809

Next, calculate the mean and standard error of the mean (SEM) for each condition.

(
    mean_rt_probe.group_by("probe")
    .agg(
        mean=pl.col("response_time").mean(),
        sem=pl.col("response_time").std() / pl.col("response_time").len().sqrt(),
    )
    .sort("probe")
)
shape: (2, 3)
probemeansem
strf64f64
"lure"1.1927780.078296
"target"1.053810.046174

When reporting your results, report the mean and SEM for each condition. For example:

Response time was faster for targets (mean: 1.054 s, SEM: 0.046 s) compared to lures (mean: 1.193 s, SEM: 0.078 s).

Analysis and reporting steps#

When analyzing the effect of some independent variable on a dependent variable, follow these steps:

  1. Calculate the means for each subject and condition.

  2. Visualize differences in means using a bar plot or line plot. Write a caption for your plot that explains the variables being plotted. If there are error bars or an error band, explain how it was calculated (for Seaborn plots, the default is to show a 95% bootstrap confidence interval).

  3. Calculate summary statistics, including the mean and SEM for each condition.

  4. Run an inferential statistical test such as a t-test or ANOVA to determine if the effect of the independent variable is statistically significant (\(p<0.05\)).

  5. Write text describing the summary statistics, including the mean and SEM for each condition. Also write about the results of the inference test, including whether the effect was significant. Report the test statistic with degrees of freedom (for example, t(32)=1.64, F(1, 32)=4.42), the p-value (for example, p=0.015), and the effect size (for exmaple, Cohen’s d=0.65, ng2=0.32).

See the Reporting chapter for a walkthrough of some common cases, such as comparing two conditions, comparing more than two conditions, and testing for effects of two different factors.

Using Markdown formatting#

When writing Markdown code in a README.md file or a notebook, you can use special formatting to make your text easier to read.

Use # to indicate levels of a heading, for example:

# Heading level 1
## Heading level 2
### Heading level 3

Use backticks (`) to indicate inline code, or triple backticks (```) to indicate the start and end of blocks of code.

For example, `print(“hello world”)` is formatted like print("hello world").

This raw Markdown code:

```python
print(“hello world”)
print(“hello world”)
```

is formatted like this:

print("hello world")
print("hello world")

Use dollar signs ($) to indicate math using LaTeX formatting.

For example, the raw Markdown code $\mathrm{SEM} = \frac{\sigma}{\sqrt{n}}$ is formatted like: \(\mathrm{SEM} = \frac{\sigma}{\sqrt{n}}\)