Loading packages
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 2.2.1 ✔ readr 1.1.1
## ✔ tibble 1.4.2 ✔ purrr 0.2.5
## ✔ tidyr 0.8.1 ✔ stringr 1.3.1
## ✔ ggplot2 2.2.1 ✔ forcats 0.3.0
## ── Conflicts ────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(lme4)
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following object is masked from 'package:tidyr':
##
## expand
library(lmerTest)
##
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
library(sjstats)
library(jmRtools)
library(MuMIn)
library(konfound)
## Sensitivity analysis as described in Frank, Maroulis, Duong, and Kelcey (2013) and in Frank (2000).
## For more information visit https://jmichaelrosenberg.shinyapps.io/shinykonfound/.
Loading data
SciMo_esm <- read_csv("/Volumes/SCHMIDTLAB/PSE/Data/SciMo/Sci-Mo-esm.csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## stud_ID = col_character(),
## teacher_ID = col_integer(),
## subject = col_integer(),
## month = col_integer(),
## day = col_integer(),
## year = col_integer(),
## pager = col_integer(),
## Wave = col_integer(),
## part_stat = col_integer(),
## gender = col_integer(),
## race = col_integer(),
## grade = col_integer(),
## age = col_integer(),
## beep = col_integer(),
## lecture = col_integer(),
## lab = col_integer(),
## manage = col_integer(),
## present = col_integer(),
## seat = col_integer(),
## test = col_integer()
## # ... with 3 more columns
## )
## See spec(...) for full column specifications.
SciMo_student_survey <- read_csv("/Volumes/SCHMIDTLAB/PSE/Data/SciMo/Sci-Mo-student-survey.csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## stud_ID = col_character(),
## FirstQuar_2010 = col_integer(),
## SecondQuar_2010 = col_integer(),
## ThirdQuar_2010 = col_character(),
## FourthQuar_2010 = col_character(),
## ExploreComp_2010 = col_integer(),
## PlanComp_2010 = col_integer(),
## ACTComp_2010 = col_integer(),
## Grad_2010 = col_integer(),
## FirstQuar_2011 = col_integer(),
## SecondQuar_2011 = col_integer(),
## ThirdQuar_2011 = col_character(),
## FourthQuar_2011 = col_integer(),
## ExloreComp2011 = col_integer(),
## ExploreSciComp_2011 = col_integer(),
## PlanComp_2011 = col_integer(),
## PlanSciComp_2011 = col_integer(),
## ACTComp_2011 = col_integer(),
## ACTSciComp_2011 = col_integer(),
## Grad_2011 = col_integer()
## )
## See spec(...) for full column specifications.
Creating Variables
SciMo_esm$overall_control <- composite_mean_maker(SciMo_esm, succeed, learning, control, exp_y, exp_t)
SciMo_esm$overall_value <- composite_mean_maker(SciMo_esm, imp_y, imp_fut)
SciMo_student_survey$female <- ifelse(SciMo_student_survey$gender == 2, 1, 0)
SciMo_student_survey$minority <- ifelse(SciMo_student_survey$race == 4, 0, 1)
df <- count(SciMo_esm, stud_ID)
df<-rename(df, signals_responded_to = n)
df$response_rate <- (df$signals_responded_to/20)
Join data
SciMo_All <- left_join(SciMo_student_survey, SciMo_esm, by = "stud_ID")
SciMo_All <- left_join(SciMo_All, df, by = "stud_ID")
SciMo_Response_Rates <- left_join (SciMo_student_survey, df, by = "stud_ID")
Correlation Function
#correlation table function
corstarsl <- function(x) {
require(Hmisc)
x <- as.matrix(x)
R <- rcorr(x)$r
p <- rcorr(x)$P
## define notions for significance levels; spacing is important.
mystars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " ")))
## trunctuate the matrix that holds the correlations to two decimal
R <- format(round(cbind(rep(-1.11, ncol(x)), R), 2))[,-1]
## build a new matrix that includes the correlations with their apropriate stars
Rnew <- matrix(paste(R, mystars, sep=""), ncol=ncol(x))
diag(Rnew) <- paste(diag(R), " ", sep="")
rownames(Rnew) <- colnames(x)
colnames(Rnew) <- paste(colnames(x), "", sep="")
## remove upper triangle
Rnew <- as.matrix(Rnew)
Rnew[upper.tri(Rnew, diag = TRUE)] <- ""
Rnew <- as.data.frame(Rnew)
## remove last column and return the matrix (which is now a data frame)
Rnew <- cbind(Rnew[1:length(Rnew)-1])
return(Rnew)
}
Correlations
Scimo_All_Corr <- select(SciMo_All, excited, happy, frustrated, bored, overall_control, overall_value, scientist2, ACTSciComp_2010)
corstarsl(Scimo_All_Corr)
## Loading required package: Hmisc
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
##
## Attaching package: 'Hmisc'
## The following object is masked from 'package:sjstats':
##
## deff
## The following objects are masked from 'package:dplyr':
##
## src, summarize
## The following objects are masked from 'package:base':
##
## format.pval, units
## excited happy frustrated bored overall_control
## excited
## happy 0.55***
## frustrated 0.00 -0.16***
## bored -0.12*** -0.22*** 0.26***
## overall_control 0.27*** 0.42*** -0.17*** -0.25***
## overall_value 0.21*** 0.24*** -0.01 -0.25*** 0.41***
## scientist2 0.13*** 0.09*** 0.02 -0.10*** 0.08***
## ACTSciComp_2010 -0.08*** 0.01 -0.09*** 0.04 0.07**
## overall_value scientist2
## excited
## happy
## frustrated
## bored
## overall_control
## overall_value
## scientist2 0.20***
## ACTSciComp_2010 -0.14*** -0.09***
Descriptives
psych::describe(SciMo_esm$excited)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 4058 0.84 1.01 0 0.69 0 0 3 3 0.86 -0.55 0.02
psych::describe(SciMo_esm$happy)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 4080 1.51 1.04 1 1.52 1.48 0 3 3 0.01 -1.17
## se
## X1 0.02
psych::describe(SciMo_esm$frustrated)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 4077 0.61 0.88 0 0.44 0 0 3 3 1.31 0.71 0.01
psych::describe(SciMo_esm$bored)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 4043 1.33 1.14 1 1.29 1.48 0 3 3 0.23 -1.35
## se
## X1 0.02
psych::describe(SciMo_esm$overall_control)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 4099 1.77 0.8 1.8 1.81 0.89 0 3 3 -0.4 -0.47 0.01
psych::describe(SciMo_esm$overall_value)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 3996 1.15 0.92 1 1.08 1.48 0 3 3 0.36 -0.91
## se
## X1 0.01
psych::describe(SciMo_student_survey$scientist2)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 215 1.54 0.73 1 1.42 0 1 4 3 1.15 0.55 0.05
psych::describe(SciMo_student_survey$ACTSciComp_2010)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 113 19.05 4.09 19 18.93 2.97 10 33 23 0.56 1.31
## se
## X1 0.38
Missing Data Analysis
SciMo_esm$missing_frustrated <- is.na(SciMo_esm$frustrated)
table(SciMo_esm$missing_frustrated)
##
## FALSE TRUE
## 4077 58
SciMo_esm$missing_bored <- is.na(SciMo_esm$bored)
table(SciMo_esm$missing_bored)
##
## FALSE TRUE
## 4043 92
SciMo_esm$missing_happy <- is.na(SciMo_esm$happy)
table(SciMo_esm$missing_happy)
##
## FALSE TRUE
## 4080 55
SciMo_esm$missing_excited <- is.na(SciMo_esm$excited)
table(SciMo_esm$missing_excited)
##
## FALSE TRUE
## 4058 77
SciMo_esm$missing_control <- is.na(SciMo_esm$overall_control)
table(SciMo_esm$missing_control)
##
## FALSE TRUE
## 4099 36
SciMo_esm$missing_value <- is.na(SciMo_esm$overall_value)
table(SciMo_esm$missing_value)
##
## FALSE TRUE
## 3996 139
SciMo_student_survey$missing_scientist2 <- is.na (SciMo_student_survey$scientist2)
table(SciMo_student_survey$missing_scientist2)
##
## FALSE TRUE
## 215 36
Missing Data Analysis
t.test(SciMo_Response_Rates$response_rate ~ SciMo_Response_Rates$female)
##
## Welch Two Sample t-test
##
## data: SciMo_Response_Rates$response_rate by SciMo_Response_Rates$female
## t = 0.6154, df = 235.34, p-value = 0.5389
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.03778719 0.07211816
## sample estimates:
## mean in group 0 mean in group 1
## 0.8554264 0.8382609
t.test(SciMo_Response_Rates$response_rate ~ SciMo_Response_Rates$minority)
##
## Welch Two Sample t-test
##
## data: SciMo_Response_Rates$response_rate by SciMo_Response_Rates$minority
## t = 0.86067, df = 183.06, p-value = 0.3905
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.03208678 0.08174094
## sample estimates:
## mean in group 0 mean in group 1
## 0.8655556 0.8407285
t.test(SciMo_Response_Rates$response_rate ~ SciMo_Response_Rates$Lunch)
##
## Welch Two Sample t-test
##
## data: SciMo_Response_Rates$response_rate by SciMo_Response_Rates$Lunch
## t = -0.0085538, df = 230.6, p-value = 0.9932
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.05328218 0.05282155
## sample estimates:
## mean in group 0 mean in group 1
## 0.8551095 0.8553398
fit<-aov(response_rate ~ grade, data = SciMo_Response_Rates)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## grade 1 0.121 0.12055 2.587 0.109
## Residuals 242 11.275 0.04659
## 7 observations deleted due to missingness
SciMo_Response_Rates$age <- as.factor(SciMo_Response_Rates$age)
fit2<-aov(SciMo_Response_Rates$response_rate ~ SciMo_Response_Rates$age)
summary(fit2)
## Df Sum Sq Mean Sq F value Pr(>F)
## SciMo_Response_Rates$age 4 0.949 0.23732 5.43 0.000335 ***
## Residuals 239 10.446 0.04371
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 7 observations deleted due to missingness
TukeyHSD(fit2)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = SciMo_Response_Rates$response_rate ~ SciMo_Response_Rates$age)
##
## $`SciMo_Response_Rates$age`
## diff lwr upr p adj
## 15-14 -0.008754098 -0.1078349 0.090326749 0.9992272
## 16-14 -0.060197183 -0.1553524 0.034957995 0.4121629
## 17-14 -0.161741935 -0.2844455 -0.039038348 0.0032450
## 18-14 -0.260666667 -0.5044770 -0.016856362 0.0294814
## 16-15 -0.051443085 -0.1517680 0.048881802 0.6221896
## 17-15 -0.152987837 -0.2797425 -0.026233171 0.0091985
## 18-15 -0.251912568 -0.4977866 -0.006038536 0.0416292
## 17-16 -0.101544752 -0.2252551 0.022165550 0.1630289
## 18-16 -0.200469484 -0.4447880 0.043849025 0.1633149
## 18-17 -0.098924731 -0.3552316 0.157382108 0.8262956