#New Statistics Short Course #Exercise 3 #CIs, Effect Sizes, #CIs for Effect Sizes dat<-read.csv(file.choose()) #mta_church names(dat) #### Part a (One-Sample) #80% t.test(dat$mot_apol[dat$group=="church"], conf.level=.80)$conf.int #95% t.test(dat$mot_apol[dat$group=="church"], conf.level=.95)$conf.int #The 95% CI is wider; if we need 95% of #intervals to contain the population #parameter, instead of just 80%, then #the interval must be wider. #This is a function of the larger #critical value at alpha=.05 than #at alpha=.20 #### Part b (Two-Sample) #Let's reduce the sample size #Original (N=1000) t.test(dat$mot_apol ~ dat$group, conf.level=.90)$conf.int #N=100 library(dplyr) dat2<-sample_n(dat,100) t.test(dat2$mot_apol ~ dat2$group, conf.level=.90)$conf.int #Smaller n means a larger standard #error and a larger critical value, #both of these mean a wider interval #### Part c #If we conducted the study over and #over again, 90% of the CIs would #contain the true population parameter #(in this case mu1-mu2) #Even more important for a researcher #is to interpret the width of the CI #and how that affects the conclusions #### Part d #raw mean difference mean(dat$mot_apol[dat$group=="church"])-mean(dat$mot_apol[dat$group=="nochurch"]) #standardized mean difference library(psych) cohen.d(dat,"group",alpha=.1) #percent of variance explained library(lsr) mod<-aov(mot_apol ~ group, data=dat) etaSquared(mod)[1] #r (or % of SD explained) library(psych) d2r(.2) cohen.d(dat,"group")$r #### Part e cohen.d.ci(d=.2,n=1000,alpha=.1) library(MBESS) #need the F value (and df) summary(mod) ci.pvaf(F.value=10.28,df.1=1,df.2=998,conf.level=.9,N=1000) #by simuation library(dplyr) etasq<-numeric(1000) for (i in 1:1000) { newdat<-sample_n(dat,size=1000,replace=TRUE) newmod<-aov(mot_apol~group,data=newdat) etasq[i]<-etaSquared(newmod)[1] } quantile(etasq,c(.05,.95)) #### Part f library(canprot) CLES(dat$mot_apol[dat$group=="church"],dat$mot_apol[dat$group=="nochurch"]) #The probability of the score being #higher for a subject from the #"nochurch" group, if one subject was #randomly selected from each group