Data
1. Pearson correlation coefficients
2. Linear model
3. Variance Inflation Factor - VIF
4. Stepwise regression
The above example is contained in the paragraph 4.3 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.
test = c(5.5, 6, 7, 5, 8, 2, 9, 10, 2, 3, 4, 6.5, 8.5, 1)
exam = c(6.5, 6, 8, 7.5, 7, 4, 8, 10, 1, 5, 5, 6, 9, 5)
gender = c(0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1)
gender = factor(gender, levels = c(0, 1), labels = c("Woman", "Man"))
absences = c(2, 3, 1, 1, 2, 5, 0, 0, 7, 5, 4, 3, 0, 4)
1. Pearson correlation coefficients
cor.test(exam, test)
cor.test(exam, absences)
cor.test(test, absences)
2. Linear model
fit = lm(exam ~ test + gender + absences)
summary(fit)
layout(matrix(c(1,2,3,4),2,2))
plot(fit)
3. Variance Inflation Factor - VIF
library(car)
vif(fit)
4. Stepwise regression
step(fit, direction="both") # or direction = "forward" or direction = "backward"
The above example is contained in the paragraph 4.3 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.
Comments
Post a Comment