library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(EnvStats)
##
## Attaching package: 'EnvStats'
##
## The following objects are masked from 'package:stats':
##
## predict, predict.lm
##
## The following object is masked from 'package:base':
##
## print.default
library(infer)
msd <- read.csv("msdlabs_race_arrest_clean.csv")
### Test self concept against IQ
iq <- lm(formula = selfconcept ~ iq, data = msd)
summary (iq)
##
## Call:
## lm(formula = selfconcept ~ iq, data = msd)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3174 -0.3213 -0.3058 0.6810 0.7158
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.2379142 0.1148582 28.191 <2e-16 ***
## iq 0.0007718 0.0011208 0.689 0.491
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6488 on 1554 degrees of freedom
## Multiple R-squared: 0.0003051, Adjusted R-squared: -0.0003382
## F-statistic: 0.4742 on 1 and 1554 DF, p-value: 0.4911
### Calculate Cohen's f
1-.0003382
## [1] 0.9996618
.0003382/.9996618
## [1] 0.0003383144
sqrt(0.0003383144)
## [1] 0.01839332
### IQ appears to be a very weak predictor of self concept.
### Test self concept against HOUSEHOLD
hh <- lm(formula = selfconcept ~ household, data = msd)
summary (hh)
##
## Call:
## lm(formula = selfconcept ~ household, data = msd)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3018 -0.3190 -0.2947 0.6810 0.7167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.2832862 0.0241854 135.755 <2e-16 ***
## household 0.0007137 0.0003849 1.855 0.0638 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6482 on 1554 degrees of freedom
## Multiple R-squared: 0.002208, Adjusted R-squared: 0.001566
## F-statistic: 3.439 on 1 and 1554 DF, p-value: 0.06385
### Calculate Cohen's f
1-.001566
## [1] 0.998434
.001566/.998434
## [1] 0.001568456
sqrt (0.001568456)
## [1] 0.03960374
### The conclusion is household income is a very weak predictor of self concept.
### Test self concept against schlbelong
school <- lm(formula = selfconcept ~ schlbelong, data = msd)
summary (school)
##
## Call:
## lm(formula = selfconcept ~ schlbelong, data = msd)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.76379 -0.32467 -0.04423 0.67533 1.51665
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.4834 0.0608 40.84 <2e-16 ***
## schlbelong 0.2804 0.0198 14.16 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6107 on 1554 degrees of freedom
## Multiple R-squared: 0.1144, Adjusted R-squared: 0.1138
## F-statistic: 200.7 on 1 and 1554 DF, p-value: < 2.2e-16
### Calculate Cohen's f
1-.1138
## [1] 0.8862
.1138/.8862
## [1] 0.1284135
sqrt(0.1284135)
## [1] 0.3583483
### This is the strongest effect size yet. A feeling of belonging at school seems to have a
### large positive effect on self concept.
### Test self concept against connection to family
family <- lm(formula = selfconcept ~ famconnect, data = msd)
summary (family)
##
## Call:
## lm(formula = selfconcept ~ famconnect, data = msd)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8267 -0.2213 -0.2213 0.3840 1.1733
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.03746 0.06851 29.74 <2e-16 ***
## famconnect 0.39463 0.02064 19.12 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5839 on 1554 degrees of freedom
## Multiple R-squared: 0.1904, Adjusted R-squared: 0.1899
## F-statistic: 365.5 on 1 and 1554 DF, p-value: < 2.2e-16
### Calculate Cohen's f
1-.1899
## [1] 0.8101
.1899/.8101
## [1] 0.2344155
sqrt(0.2344155)
## [1] 0.4841647
### In this dataset, family connectedness appears to be the strongest predictor of self concept.