-
Notifications
You must be signed in to change notification settings - Fork 1
/
Homwork Assigment week 3.R
50 lines (36 loc) · 1.35 KB
/
Homwork Assigment week 3.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Statistics One, Week 3 Assignment R
#Multiple regression analysis
#load library
library(psych)
#read data into data frame called "endur"
endur <- read.table("DAA.03.txt", header=T)
#Correlation between age and endurance
cor(endur$age, endur$endurance)
#examine scatterplot
plot(endur$endurance ~ endur$age, main = "Scatterplot", ylab = "Endurance", xlab = "Age")
abline(lm(endur$endurance ~ endur$age), col-"blue")
#Simple regression
model1 = lm(endur$endurance ~ endur$age)
print(summary(model1))
model2 = lm(endur$endurance ~ endur$activeyears)
print(summary(model2))
#Multiple regression
model3 = lm(endur$endurance ~ endur$age + endur$activeyears)
print(summary(model3))
model4 = lm(endur$endurance ~ endur$activeyears + endur$age)
print(summary(model4))
#Statistics One, Week 3 exercise
#Multiple regression analysis with standardized regression coefficients
model1.z = lm(scale(endur$endurance) ~ scale(endur$age))
print(summary(model1.z))
model2.z = lm(scale(endur$endurance) ~ scale(endur$activeyears))
print(summary(model2.z))
model3.z = lm(scale(endur$endurance) ~ scale(endur$age) + scale(endur$activeyears))
print(summary(model3.z))
model4.z = lm(scale(endur$endurance) ~ scale(endur$activeyears) + scale(endur$age))
print(summary(model4.z))
#model comparisons
comp1 = anova(model1.z, model3.z)
print(comp1)
comp2 = anova(model2.z, model3.z)
print(comp2)