# Edps/Psych/Stat 587 # Computer lab 4 template # Spring 2019 # C.J.Anderson # # # # Packages: # lme4 # lmerTest # lattice # ggplot2 # stringi (this needs to be installed before HLMdiag or # HLMdiag won't load properly) # HLMdiag # # (install) and load packages require(lme4) require(lmerTest) require(HLMdiag) ############################################################################# # read in data into R # the first row of the data matrix is the variable names so there is a header # change to your path ############################################################################# lab4<-read.table("C:/Users/Carolyn/Dropbox/edps587/Lab_and_homework/Computer lab4/lab3.txt",header=TRUE) #look at first few rows of data set head(lab4) ################################################## # Set-up -- from before ################################################## # Use if statment to create "boy" lab4$boy = ifelse(lab4$gender=="boy", 1, 0) # Create Third lab4$third <- ifelse(lab4$grade==3, 1, 0) # School mean Center math and school mean math grpMmath <- as.data.frame(aggregate(math~idschool, data=lab4, "mean")) names(grpMmath) <- c('idschool', 'grpMmath') lab4 <- merge(lab4,grpMmath, by=c('idschool')) lab4$grpCmath <- lab4$math - lab4$grpMmath # # make school id a factor variable # lab4$idschool<-as.factor(lab4$idschool) # # Re-scale for latter use # lab4$gcmath <- scale(lab4$grpCmath, center=FALSE, scale=TRUE) lab4$gmmath <- scale(lab43grpMmath, center=FALSE, scale=TRUE) ################# # # # Comand to pause between figures where ENTER #gives next one. # par(ask=TRUE) ################ #This is useful after whole # program is written and want to re-run. # par(ask=TRUE) ####################################################