-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomework2final.R
112 lines (91 loc) · 3.06 KB
/
homework2final.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
pizza <- read.table('Frozen_Pizza.txt', sep = '\t', header = TRUE)
#Baltimore
plot(pizza$Baltimore.Price,pizza$Baltimore.Volume,xlab='price',ylab='volume')
#fitted model
imod <- lm(Baltimore.Volume~Baltimore.Price,data=pizza)
summary(imod)
summary(imod)$coefficients
confint(imod, level = 0.95)
#Dallas
plot(pizza$Dallas.Price,pizza$Dallas.Volume,xlab='price',ylab='volume')
#fitted model
imod2 <- lm(Dallas.Volume~Dallas.Price,data=pizza)
summary(imod2)
summary(imod2)$coefficients
confint(imod2, level = 0.95)
#chicago
plot(pizza$Chicago.Price,pizza$Chicago.Volume,xlab='price',ylab='volume')
#fitted model
imod3 <- lm(Chicago.Volume~Chicago.Price,data=pizza)
summary(imod3)
summary(imod3)$coefficients
confint(imod3, level = 0.95)
#Denver
plot(pizza$Denver.Price,pizza$Denver.Volume,xlab='price',ylab='volume')
#fitted model
imod4<- lm(Denver.Volume~Denver.Price,data=pizza)
summary(imod4)
summary(imod4)$coefficients
confint(imod4, level = 0.95)
#2
#Baltimore
pizza$Week <- as.Date(pizza$Week,format = "%m/%d/%y")
par(mfrow = c(1, 2))
plot(pizza$Week,imod$residuals,xlab = 'Time', ylab = 'Residual')
abline(a = 0, b = 0)
plot(imod$fitted.values, imod$residuals, xlab = 'Fitted value', ylab = 'Residual')
abline(a = 0, b = 0)
#Q-Q plot Baltimore
par(mfrow = c(1, 2))
hist(imod$residuals, xlab = 'Residual', main = 'Histogram of Residuals')
qqnorm(imod$residuals)
qqline(imod$residuals)
#Dallas
par(mfrow = c(1, 2))
plot(pizza$Week,imod2$residuals,xlab = 'Time', ylab = 'Residual')
abline(a = 0, b = 0)
plot(imod2$fitted.values, imod2$residuals, xlab = 'Fitted value', ylab = 'Residual')
abline(a = 0, b = 0)
#QQ plot
par(mfrow = c(1, 2))
hist(imod2$residuals, xlab = 'Residual', main = 'Histogram of Residuals')
qqnorm(imod2$residuals)
qqline(imod2$residuals)
#Chigago
par(mfrow = c(1, 2))
plot(pizza$Week,imod3$residuals,xlab = 'Time', ylab = 'Residual')
abline(a = 0, b = 0)
plot(imod3$fitted.values, imod3$residuals, xlab = 'Fitted value', ylab = 'Residual')
abline(a = 0, b = 0)
#QQ plot
par(mfrow = c(1, 2))
hist(imod3$residuals, xlab = 'Residual', main = 'Histogram of Residuals')
qqnorm(imod3$residuals)
qqline(imod3$residuals)
#Denver
par(mfrow = c(1, 2))
plot(pizza$Week,imod4$residuals,xlab = 'Time', ylab = 'Residual')
abline(a = 0, b = 0) > plot(imod4$fitted.values, imod4$residuals, xlab = 'Fitted value', ylab = 'Residual')
abline(a = 0, b = 0)
#QQ Plot
par(mfrow = c(1, 2))
hist(imod4$residuals, xlab = 'Residual', main = 'Histogram of Residuals')
qqnorm(imod4$residuals)
qqline(imod4$residuals)
#3
confint(imod2, level = 0.90)
#4
imod2 <- lm(pizza$Dallas.Volume~pizza$Dallas.Price,data=pizza)
summary(imod2)
#5
# if the price is $2.5
range(pizza$Dallas.Price)
new<-data.frame(Dallas.Price=c(2.50))
predict(imod2,newdata = new,interval='confidence',level=0.95)
#if the price is $3
new1<-data.frame(Dallas.Price=c(3.00))
predict(imod2,newdata = new1,interval='confidence',level=0.95)
#6
dallasnew <-lm(pizza$Dallas.Volume~pizza$Dallas.Price,data=pizza)
new2<-data.frame(Dallas.Price=c(2.99))
predict(dallasnew,newdata = new2,interval='prediction',level=0.95)