-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlc.R
49 lines (30 loc) · 1.07 KB
/
tlc.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
tlc <- read.csv("tlc.csv", header=T)
x <- tlc$lot; y <- tlc$hours
reg <- lm(y~x)
sm <- summary(reg)
### estimated variance
sm$sigma^2
### p-value for H0: Beta 1 = 4
2*pt(1.228571, 23, lower.tail=F)
### p-value for H0: Beta 1 <= 4
pt(-1.23, 23)
### Confidence interval for Beta 0
confint(reg, level=0.95)
confint(reg, level=0.90)
### Confidence interval for estimate at x=65
new = data.frame(x = 65)
predict(reg, new, se.fit=T, interval="confidence", level=0.9)
### prediction interval
new = data.frame(x = 100)
predict(reg, new, se.fit=T, interval="prediction", level=0.9)
### 90% confidence in the estimate
predict(reg, new, se.fit=T, interval="confidence", level=0.9)
plot(reg) ## first plot is residuals vs. fitted; check for constant variance (scattered around 0 line)
yhat <- fitted(reg) ## can get first plot without plot(reg), using e below
e <- residuals(reg)
plot(x, e) ## scattered around 0 line -> constant variance
## look for outliers
## b$out == 0 indicates no outliers
b <- boxplot(e, horizontal=T)
## can use instead of QQ Norm in plot(reg)
qqnorm(e); qqline(e)