
---
# PSYCH 10 final report (M10), formatted as an APA 7 student paper. Knit to PDF
# (Session -> Restart R, then Knit -> Knit to PDF). Edit the title page in
# the first code block below; leave this header alone unless you know LaTeX.
output:
  pdf_document:
    latex_engine: pdflatex
    fig_caption: true
    number_sections: false
fontsize: 12pt
fontfamily: times
geometry: margin=1in
indent: true
header-includes:
  - \usepackage{setspace}
  - \doublespacing
  - \usepackage{fancyhdr}
  - \pagestyle{fancy}
  - \fancyhf{}
  - \fancyhead[R]{\thepage}
  - \renewcommand{\headrulewidth}{0pt}
  - \setlength{\headheight}{15pt}
  - \makeatletter
  - \renewcommand\section{\@startsection{section}{1}{\z@}{0.5\baselineskip}{0.1\baselineskip}{\normalfont\normalsize\bfseries\centering}}
  - \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{0.5\baselineskip}{0.1\baselineskip}{\normalfont\normalsize\bfseries}}
  - \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{0.5\baselineskip}{0.1\baselineskip}{\normalfont\normalsize\bfseries\itshape}}
  - \makeatother
  - \usepackage{caption}
  - \captionsetup[figure]{labelfont=bf,textfont=it,labelsep=newline,justification=raggedright,singlelinecheck=false}
  - \captionsetup[table]{labelfont=bf,textfont=it,labelsep=newline,justification=raggedright,singlelinecheck=false}
  - \usepackage{floatrow}
  - \floatsetup[figure]{capposition=top}
  - \floatsetup[table]{capposition=top}
  - \usepackage{booktabs}
  - \usepackage{indentfirst}
---

```{r setup, include = FALSE}
# Code is shown in the knit report (echo = TRUE), so your TA can read it next
# to the results. Messages and warnings are hidden.
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE,
                      fig.width = 6, fig.height = 3.8)
library(coursekata)
library(here)
```

```{=latex}
% ---- Title page. Edit the four \newcommand lines; leave the rest. ----
\newcommand{\papertitle}{The Title of Your Report, in Title Case}
\newcommand{\paperauthors}{First Author, Second Author, and Third Author}
\newcommand{\sectionleader}{Your section leader's name}
\newcommand{\duedate}{December 8, 2026}
\begin{center}
\vspace*{3\baselineskip}
{\bfseries \papertitle}\par
\vspace{\baselineskip}
\paperauthors\par
Department of Psychology, Stanford University\par
PSYCH 10: Introduction to Statistical Methods\par
Instructor: Judith Fan; section leader: \sectionleader\par
\duedate
\end{center}
\newpage
\begin{center}{\bfseries \papertitle}\end{center}
```

<!--
HOW TO USE THIS TEMPLATE

This is your final report, written as one APA-style paper. APA style is the
format that the American Psychological Association sets for papers in
psychology: the title page, the headings, the citations, the references, and
the figures and tables. This template already applies the format. For an
explanation with sample papers, see
https://apastyle.apa.org/style-grammar-guidelines/paper-format and, for the
format of each reference,
https://apastyle.apa.org/style-grammar-guidelines/references/examples

The report brings together
what you did in the milestones: your dataset, two
questions and the DGPs (M4), the data dictionary and prepare-data.R (M5), the
model and the shuffles (M6), and your figures (M7). You can copy from your
milestones, but the report should give your final decisions, even if they
changed since then, and it should read as one paper, not a list of answers.

- Each numbered comment like this one (I.1, M.2, R.3, ...) is a prompt, with
  its points and the milestone it builds on. The comments do not appear in
  the PDF. Replace every [...] with your own text.
- Write for a reader who has not taken PSYCH 10: full sentences, plain words,
  every number with its units.
- Throughout, replace Thumb (the outcome), Sex (the explanatory variable), and
  Job (the question 2 variable) with your own variables, and the Fingers data
  with yours.
- About 1,500-2,000 words, plus figures and tables. The report is scored out
  of 40 points.
- Knit to PDF from a fresh session (Session -> Restart R, then Knit -> Knit to
  PDF). One member submits the PDF and this .Rmd on Gradescope and adds the
  other members.
-->

```{r data}
# Rebuild data/processed/ from data/raw/ and run your checks (prepare-data.R
# runs R/checks.R), then load the processed data. Every number in this report
# comes from this file.
# Take the # off the next two lines and delete the "processed <- Fingers" line:

# as a reminder, this line re-runs prepare-data.R and re-makes your processed data:
# source(here("R", "prepare-data.R")) 
# processed <- read.csv(here("data", "processed", "processed-data.csv"))
processed <- Fingers
```

<!-- INTRODUCTION (7 points). In APA style the introduction has no heading:
it starts right under the title. -->

<!-- I.1 (2 points; builds on M1-M3). 

- Write the claim you were inspired by, as its source stated it, with the number 
it rests on and where it appeared. Cite the source in APA in-text format and put
the APA citation in the references section at the bottom of this report. 
- Describe who the claim is about, and why it is worth checking. 

If your group does not have a clear claim, that's fine. Just give a few 
sentences of background on what inspired your main questions, and cite at least
one source in this background.
-->

[...]

<!-- I.2 (3 points; builds on M4). 

Write your first question: how does your explanatory variable predict your 
outcome? 

- Name both variables. 
- State your hypothesis for this question: the direction you
predicted and its rough size, in the outcome's units, as you wrote it in M4.
- Write the data-generating process (DGP) you think would produce that 
relationship.
-->

[...]

<!-- I.3 (2 points; builds on M4). 

Write at least two other DGPs that could produce the same relationship, and how 
each differs from your hypothesized one.

Then write your second question, which builds on one of these alternatives, and 
the variable it brings in. 

End the introduction with one sentence revealing what you found. 
-->

[...]

# Method

<!-- METHOD (9 points). -->

## Data Source

<!-- M.1 (3 points; builds on M3 and M4). 

Describe who collected the data, when, and how, with an in-text citation. Don't 
forget to put the full citation in the References section.
- Describe what one row stands for in the raw data (a person, a country, a year)
- Describe who is in the data and who isn't (i.e. the sample collected)

-->

[...]

## Data Preparation

<!-- M.2 (2 points; builds on M5). 

Explain each step in R/prepare-data.R, as a numbered list: what you changed from
the raw data (recoding, missing-value codes, renamed groups, dropped cases) and 
why. -->

1. [...]
2. [...]

```{r sample-size}
# The number of cases in the processed data:
nrow(processed)
```

## Measures

<!-- M.3 (2 points; builds on the data dictionary from M5).

For each variable in your two questions: write its name in the processed data,
what it measures, and its units or categories. 
- If a variable came from a second source, say where.

-->

[...]


## Analysis

<!-- M.4 (2 points; builds on M6). 

Write the model you fit for question 1, as a word equation (outcome = 
explanatory variable + other stuff) and in R. Describe (based on code you'll 
write below in the Results section): 
- how you judged the strength of the relationship (PRE, F, and the 
p-value from supernova()
- the 95% confidence interval for b1
- the real b1 among 1,000 shuffled ones

Also explain how you investigated question 2 (did you fit a model, was it 
qualitative, etc). 

Describe anything about the questions or the analysis that changed since the 
milestones, and why. 

-->

[...]

# Results

<!-- RESULTS (15 points). 

For this section you will need to edit the code AND fill in your answers for 
that question / relevant to the code you wrote in the [...] section right 
underneath. 

-->

<!-- R.1 (1 point; builds on M5). 

Print a table of summary statistics for the outcome (by group, for a categorical
explanatory variable), and one sentence on what it shows.

-->

```{r table1}
# change the code here to be relevant to your vars of interest
knitr::kable(favstats(Thumb ~ Sex, data = processed)[, c("Sex", "n", "mean", "sd")],
             booktabs = TRUE, digits = 1, row.names = FALSE,
             caption = "Thumb Length (mm) by Sex in the Fingers Data")
```

[...]

## Question 1: [Write Out Your First Question in Words, in Title Case]

<!-- R.2 (2 points; builds on M7). 

Plot your figure 1 from M7, with the changes your TA suggested: the outcome on 
the y-axis, the model drawn on the data, axes in
words with units, group names in words, readable text. 

The chunk's fig.cap is the figure's title, in title case. Refer to it in the 
text as Figure 1, with your take-home sentence.

-->

```{r figure1, fig.cap = "Thumb Length by Sex in the Fingers Data"}
q1_model <- lm(Thumb ~ Sex, data = processed)

gf_jitter(Thumb ~ Sex, data = processed, width = 0.1, alpha = 0.5) %>%
  gf_model(q1_model) %>%
  gf_labs(x = "Sex", y = "Thumb length (mm)") %>%
  gf_theme(theme_classic(base_size = 12))
```

[...]

<!-- R.3 (3 points; builds on M6). 

Type out the estimates, in sentences with numbers and units: 
- b0 (for a group model, the 
mean of the reference group, named; for a regression, the prediction when the 
explanatory variable is 0, and whether 0 is inside its range) 
- b1 (the 
difference between groups, or the change in the outcome for each one-unit 
increase). 

-->

```{r q1-model}
q1_model
```

[...]

<!-- R.4 (3 points; builds on M6). 

Write out the strength of the relationship: PRE, F, and the p-value from 
supernova(), in APA form, for example F(1, 155) = 25.3,
p < .001, PRE = .14. As a rough guide, PRE from
.01 to .09 is often called small, .09 to .25 medium, and .25 or more large.
How big is yours, and what does it mean in plain words for someone who hasn't
taken PSYCH 10? 

-->

```{r q1-strength}
supernova(q1_model)
```

[...]

<!-- R.5 (3 points; builds on M6, with CourseKata Ch 10 and 12). 

Could chance alone produce a b1 this far from 0?

Find (using the code) and describe:
- the proportion of 1,000 shuffled b1s at least as far from 0 as your real b1, 
and what it means
- how it compares with the p-value
- the 95% confidence interval for b1 from confint(), in APA
form (for example b1 = 6.4 mm, 95% CI [4.1, 8.7]). This represents the range
of DGP values your data are consistent with.

The histogram of the shuffled b1s is in the Appendix (Figure A1); refer to it
here.

-->

```{r q1-shuffles}
set.seed(10)   # the same shuffles every time you knit
sample_b1 <- b1(Thumb ~ Sex, data = processed)
shuffled_b1s <- do(1000) * b1(shuffle(Thumb) ~ Sex, data = processed)
mean(abs(shuffled_b1s$b1) >= abs(sample_b1))

confint(q1_model)
```

[...]

## Question 2: [Your Second Question, in Title Case]

<!-- R.6 (3 points; builds on M6 and M7). 

Analyze the question 1 relationship within each group of the question 2 
variable: print and describe b1 in each group, and whether it is
about the same in every group or differs in direction or size.

Include your Figure 2 from M7, refer to it in the text, and give its take-home 
sentence.

There are two ways to answer question 2, and both can earn full points. If
your question 2 variable is in your dataset, do the analysis above. If your
question 2 variable is not in your dataset, delete the two chunks below and
write your answer instead: name the variable you would need, describe how a
study could measure it, describe the pattern you would expect to see, and
explain why that pattern would help you decide between your DGPs.
-->

```{r question-2}
# b1 for the question 1 model within each group (one line per group, with your
# group names):
#   b1(Thumb ~ Sex, data = filter(processed, Job == "a group name"))
favstats(Thumb ~ Sex + Job, data = processed)
```

```{r figure2, fig.cap = "Thumb Length by Sex Within Each Job Category", fig.width = 7.5}
gf_jitter(Thumb ~ Sex, data = processed, width = 0.1, alpha = 0.5) %>%
  gf_facet_grid(. ~ Job) %>%
  gf_labs(x = "Sex", y = "Thumb length (mm)") %>%
  gf_theme(theme_classic(base_size = 12))
```

[...]

# Discussion

<!-- DISCUSSION (9 points). -->

<!-- D.1 (2 points; builds on M6). 

Was your hypothesis supported? Compare the
direction and the size you predicted in M4 with what you found, giving both
numbers. If they differ, that difference is a finding; don't revise the
prediction. 

-->

[...]

<!-- D.2 (3 points; builds on M4 and M6). 

Which of your DGPs survive your
results, which they rule out, and which your data cannot tell apart, with the
evidence for each (the model, the shuffles, the interval, question 2). 

A rare
shuffle result rules out chance alone, not a third variable or the reverse
direction. Which DGP do you now think is most likely, and why? 

-->

[...]

<!-- D.3 (2 points).

One meaningful limitation, beyond "the sample could be
larger": who was counted and who wasn't, how the variables were measured, or
what you excluded. 

Then a follow-up study that would address it: what you
would measure or change, and how the result would help you tell your DGPs
apart. 

-->

[...]

<!-- D.4 (2 points). 

Your take-home message, in one sentence: the direction
and the size of the relationship, in the outcome's units, with its
uncertainty, and no more general than your data allow (the people or places
your data cover, not "everyone"). 

Does the claim from the introduction hold
up? (if you had one)-->

[...]

\newpage

# References

<!-- Add your references (in APA format) here -->



\newpage

# Appendix

## Figure A1

```{r figureA1, fig.cap = "The Real $b_1$ Among 1,000 $b_1$s From Shuffled Data"}
gf_histogram(~ b1, data = shuffled_b1s) %>%
  gf_point(x = sample_b1, y = 0, color = "red", size = 3) %>%
  gf_labs(x = "b1 from shuffled data (mm)", y = "Number of shuffles")
```

## Data Preparation Code

<!-- This prints R/prepare-data.R so your TA can read each step from M.2. -->

```{r prepare-data-code, eval = FALSE, code = readLines(here("R", "prepare-data.R"))}
```

## AI Use Statement

<!-- Required (not scored separately). How your group used AI tools on the
project and on this report, and how you checked what they gave you. -->

[...]
