-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Module-3-Example-2.R
61 lines (36 loc) · 1.15 KB
/
Module-3-Example-2.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
50
51
52
53
54
55
56
57
58
59
60
61
# setwd("SET THE Working Director to THE PATH TO THIS DIRECTORY")
student <- read.csv("Datasets/students.csv")
student
attach(student)
study.hours<-hours
plot(hours, score, main="Scatterplot of exam score vs. hours of study", xlab="Hours of study", ylab="Score",
xlim=c(0,10), ylim=c(40,100), pch=1, col="red", cex.lab=1.5)
#calculate sample correlation
cor(study.hours, score)
cor(score, study.hours)
a<-cor(score, study.hours)
print(a)
my.model<-lm(student$score~student$hours)
# print the linearValues
print(my.model)
# or and use the intercept and score to draw a line
# abline(51.515, 5.012)
# OR
# or just pass the result values of the lm function to draw a line
abline(my.model)
# Calculate Confidence Intervals for Model Parameters
confint(my.model)
?confint
# default level is .95
confint(my.model, level = .90)
# report a summary of my model
summary(my.model)
# create Analysis of Variance Table
anova(my.model)
# fitted values of my model
fitted(my.model)
# residuals of my model
resid(my.model)
# As an extra task for you
# Describe what are these plots
plot(my.model)