Created
September 7, 2025 19:34
-
-
Save sarah-gripshover-PERTS/a7da2b60c3ee8fed2adf9dafcfb57631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library("tidyverse") | |
| library("MASS") | |
| #GPr Gpo #belPr #gmsPr gmspo belpo | |
| mat <- c(1, .7, .15, .21, .2, .14, # GPr | |
| .7, 1, .17, .38, .22, .15, # Gpo | |
| .15, .17, 1, .5, .41, .85, # belPr | |
| .21, .19, .38, 1, .91, .32, # gmsPr | |
| .18, .22, .41, .91, 1, .35, # gmspo | |
| .2, .22, .85, .32, .35, 1 # belpr | |
| ) | |
| S <- matrix(mat, nrow = sqrt(length(mat)), ncol = sqrt(length(mat))) | |
| mus <- c(3, # GPA_pre | |
| 3, # GPA_post, | |
| 4.5, # belonging pre | |
| 4.7, # growth mindset pre | |
| 4.5, # belonging post | |
| 4.7) # growth mindset post | |
| # assemble the data | |
| fake_data <- mvrnorm(n = n_obs, mu = mus, Sigma = S) %>% | |
| data.frame() %>% | |
| setNames(c("GPA_pre", "GPA_post", "belonging_pre", "growth_mindset_pre", | |
| "belonging_post", "growth_mindset_post")) %>% | |
| mutate(subject_id = 1:nrow(.), | |
| treatment = rep(c("curriculum A", "curriculum B"), nrow(.)/2)) | |
| # now build in some interesting effects | |
| # let's say the treatment has a small effect on growth mindset, belonging, and GPA | |
| GPA_post_B <- fake_data$GPA_post[fake_data$treatment == "curriculum B"] | |
| GPA_effect <- rnorm(nrow(fake_data)/2, mean = .08, sd = .25) | |
| fake_data$GPA_post[fake_data$treatment == "curriculum B"] <- GPA_post_B + GPA_effect | |
| gms_post_B <- fake_data$growth_mindset_post[fake_data$treatment == "curriculum B"] | |
| gms_effect <- rnorm(nrow(fake_data)/2, mean = .16, sd = .25) | |
| fake_data$GPA_pre[fake_data$treatment == "curriculum B"] <- gms_post_B + gms_effect | |
| bel_post_B <- fake_data$belonging_post[fake_data$treatment == "curriculum B"] | |
| bel_effect <- rnorm(nrow(fake_data)/2, mean = .16, sd = .25) | |
| fake_data$GPA_pre[fake_data$treatment == "curriculum B"] <- bel_post_B + bel_effect | |
| # now check | |
| lm(GPA_post ~ treatment, data = fake_data) %>% | |
| summary() | |
| # Coefficients: | |
| # Estimate Std. Error t value Pr(>|t|) | |
| # (Intercept) 2.98240 0.04409 67.645 <2e-16 *** | |
| # treatmentcurriculum B 0.16082 0.06235 2.579 0.01 * | |
| # --- | |
| # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 | |
| # | |
| # Residual standard error: 0.9859 on 998 degrees of freedom | |
| # Multiple R-squared: 0.006622, Adjusted R-squared: 0.005627 | |
| # F-statistic: 6.653 on 1 and 998 DF, p-value: 0.01004 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment