forked from duongnguyen/Statistics-One
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Homwork Excercise week 4 mod.R
35 lines (25 loc) · 808 Bytes
/
Homwork Excercise week 4 mod.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#Statistics One Week 4
#Moderation analysis
#Load library
library(psych)
#Load file to data frame
mod <- read.table("supplemental_STATS1.EX.06.txt", header=TRUE)
#descriptive statistics
print(describe(mod))
layout(matrix(c(1,2,3,4,5,6),2,3,byrow=T)) #create blank page
hist(mod$happy)
hist(mod$extra)
hist(mod$diverse)
#scatterplots to test linear and plot(med$happy ~ med$extra)
abline(lm(mod$happy ~ mod$extra))
plot(mod$diverse ~ mod$extra)
abline(lm(mod$diverse ~ mod$extra))
plot(mod$happy ~ mod$diverse)
abline(lm(mod$happy ~ mod$diverse))
#Conduct two regression analysis
no.mod.model = lm(mod$happy ~ mod$extra + mod$ses)
print(summary(no.mod.model))
mod.model = lm(mod$happy ~ mod$extra + mod$ses + mod$mod)
print(summary(mod.model))
#Compare models
print(anova(no.mod.model, mod.model))