#5710 Lab - Week of 3/9 #Import Ginzberg data set, or if you have Rcmdr running, Ginzberg is already available library(Rcmdr) #1 Regression with simplicity and fatalism predicting depression LinearModel.1 <- lm(depression ~ simplicity + fatalism , data=Ginzberg) summary(LinearModel.1) #2 Regression with simplicity, fatalism, and interaction predicting depression LinearModel.2 <- lm(depression ~ simplicity + fatalism + simplicity :fatalism , data=Ginzberg) summary(LinearModel.2) #3 Make Ginzberg the active dataset (may do so through Data/Data in packages/Read data/car) and plot the interaction via Rcmdr menu (several packages are required which it will load automatically). #4 Another plot of the interaction. Note that 'all.effects' is allEffects in more recent versions of R. attach(Ginzberg) plot(all.effects(LinearModel.2, xlevels=list(fatalism =seq(0,2,by=.5), simplicity = seq(0,3,by=.1) )), ask = F, multiline = T, colors = rainbow (10), key.args = list (x=0.05, y = 0.7, corner = c(0,0))) #5 Compare models anova(LinearModel.1,LinearModel.2) #Import Attitude data set attitude <- read.table("http://www.unt.edu/rss/class/mike/data/sobeldataset.dat", header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE) #11 Test mediation attach(attitude) library(multilevel) sobel(Attitude, Intention, Behavior)