# HW1 (Due Sep 13) Key # Change working directory to wherever your files are stored # 1. Read in data, inspect, DVs and IVs d = dfReadDat('HW1_Data.dat') ##Read in data file str(d) ##View variables # IV/predictor: Condition, PreTest # DV: PostCon, PostPerc, PostProc # 2. # a. Summary summary(d) # b. Descriptives varDescribe(d) # c. Just for pretest varDescribe(d$PreTest) # d. Histogram for pretest hist(d$PreTest, main = 'PreTest Scores') # e. diff for p. 9 d[9,'PostCon'] - d[9,'PostPerc'] # 3. mean-center pre-test d$PreTestC = d$PreTest - mean(d$PreTest) # check: mean(d$PreTestC) # 4. center condition d$ConditionC = varRecode(d$Condition,c(0,1), c(-.5, .5)) mean(d$ConditionC) # 5. global learning measure # a. d$PostTestM = rowMeans(cbind(d$PostCon, d$PostProc, d$PostPerc), na.rm=TRUE) # This is saying: combining the variables PostCon, PostProc, PostPerc into a new matrix (with only three # columns, each corrersponding to one variable) calculate the means of each row for this new matrix and # enter the value into this new variable named 'PostTestT', remove (ignore) missing values # b. varDescribe(d$PostTestM) # The mean is 73.93 and the sd is 9.74 # c. varDescribeBy(d$PostTestM, d$ConditionC) # 6. standardize postcon # a. d$PostConZ = (d$PostCon - mean(d$PostCon)) / sd(d$PostCon) # b. varDescribe(d$PostConZ) ##mean=0, sd=1 # c. str(d) #d. varDescribe(d) # 7. table varDescribe(d) ## See word key for the table # 8. plotting plot(d$PreTest, d$PostTestM, main='Mean PostTest scores as function of PreTest scores', xlab='PreTest', ylab='PostTest (composite)') abline(lm(d$PostTestM ~ d$PreTest)) # 9. outcome by condition varDescribeBy(d$PostTestM, d$Condition)