Temperature <-c(94,96,95, 108,67,88, 89, 84, 90, 106, 67, 71, 100, 79,97,98,87, 76,68,92,100, 85, 89,74, 86)
megawatts<-c(136.0, 131.7, 140.7, 189.3, 96.5, 116.4, 118.5, 113.4,132.0, 178.2, 101.6, 92.5, 151.9, 106.2, 153.2, 150.1, 114.7, 100.9, 96.3, 135.1, 143.6, 111.4,116.5,103.9, 105.1)
plot(Temperature, megawatts, main ="Scatterplot of Load vs Temp", xlab="TEMP", ylab="LOAD" )
reg_results3<-lm(megawatts ~ Temperature+I(Temperature^2)+I(Temperature^3))
summary(reg_results3)
##
## Call:
## lm(formula = megawatts ~ Temperature + I(Temperature^2) + I(Temperature^3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.3229 -2.1941 -0.1422 3.3026 9.7775
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.313e+02 4.771e+02 0.694 0.495
## Temperature -6.392e+00 1.679e+01 -0.381 0.707
## I(Temperature^2) 3.775e-02 1.945e-01 0.194 0.848
## I(Temperature^3) 8.432e-05 7.426e-04 0.114 0.911
##
## Residual standard error: 5.501 on 21 degrees of freedom
## Multiple R-squared: 0.9594, Adjusted R-squared: 0.9536
## F-statistic: 165.4 on 3 and 21 DF, p-value: 9.137e-15
reg_results2<-lm(megawatts ~ Temperature+I(Temperature^2))
summary(reg_results2)
##
## Call:
## lm(formula = megawatts ~ Temperature + I(Temperature^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.4291 -2.1779 -0.0156 3.1759 9.6489
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 385.048093 55.172436 6.979 5.27e-07 ***
## Temperature -8.292527 1.299045 -6.384 2.01e-06 ***
## I(Temperature^2) 0.059823 0.007549 7.925 6.90e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.376 on 22 degrees of freedom
## Multiple R-squared: 0.9594, Adjusted R-squared: 0.9557
## F-statistic: 259.7 on 2 and 22 DF, p-value: 4.991e-16
anova(reg_results2)
## Analysis of Variance Table
##
## Response: megawatts
## Df Sum Sq Mean Sq F value Pr(>F)
## Temperature 1 13196.4 13196.4 456.567 3.330e-16 ***
## I(Temperature^2) 1 1815.4 1815.4 62.808 6.898e-08 ***
## Residuals 22 635.9 28.9
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Average_Temp <-c(16.8, 15.0,16.5,17.7,20.6,22.6,23.3,18.2, 18.6)
Catch_Ratio <-c(.66, .30, .46, .44, .67, .99,.75, .24, .51)
reg_results54 <-lm(Catch_Ratio~ Average_Temp +I(Average_Temp^2))
summary(reg_results54)
##
## Call:
## lm(formula = Catch_Ratio ~ Average_Temp + I(Average_Temp^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.250765 -0.070461 -0.002579 0.045145 0.233726
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.091109 3.379866 0.323 0.758
## Average_Temp -0.118624 0.353664 -0.335 0.749
## I(Average_Temp^2) 0.004705 0.009103 0.517 0.624
##
## Residual standard error: 0.1705 on 6 degrees of freedom
## Multiple R-squared: 0.6038, Adjusted R-squared: 0.4717
## F-statistic: 4.571 on 2 and 6 DF, p-value: 0.0622
anova(reg_results54)
## Analysis of Variance Table
##
## Response: Catch_Ratio
## Df Sum Sq Mean Sq F value Pr(>F)
## Average_Temp 1 0.257873 0.257873 8.8758 0.02466 *
## I(Average_Temp^2) 1 0.007762 0.007762 0.2672 0.62373
## Residuals 6 0.174321 0.029053
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
cor(Average_Temp, Average_Temp^2)
## [1] 0.9981626
Temp_standard <-scale(Average_Temp)
Temp_standard
## [,1]
## [1,] -0.71513158
## [2,] -1.35519409
## [3,] -0.82180866
## [4,] -0.39510032
## [5,] 0.63611151
## [6,] 1.34729209
## [7,] 1.59620529
## [8,] -0.21730518
## [9,] -0.07506906
## attr(,"scaled:center")
## [1] 18.81111
## attr(,"scaled:scale")
## [1] 2.812225
reg_results54s <-lm(Catch_Ratio~ Temp_standard +I(Temp_standard^2))
summary(reg_results54s)
##
## Call:
## lm(formula = Catch_Ratio ~ Temp_standard + I(Temp_standard^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.250765 -0.070461 -0.002579 0.045145 0.233726
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.52470 0.08558 6.131 0.000861 ***
## Temp_standard 0.16424 0.06714 2.446 0.050032 .
## I(Temp_standard^2) 0.03721 0.07200 0.517 0.623731
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1705 on 6 degrees of freedom
## Multiple R-squared: 0.6038, Adjusted R-squared: 0.4717
## F-statistic: 4.571 on 2 and 6 DF, p-value: 0.0622
anova(reg_results54s)
## Analysis of Variance Table
##
## Response: Catch_Ratio
## Df Sum Sq Mean Sq F value Pr(>F)
## Temp_standard 1 0.257873 0.257873 8.8758 0.02466 *
## I(Temp_standard^2) 1 0.007762 0.007762 0.2672 0.62373
## Residuals 6 0.174321 0.029053
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
State_installation <-c(198,126,443,570,286,184,105,216,465,203, 563,314,483,144,585,377, 264,185,330,354, 385,693,266,586,178, 773,308,430,644,515)
state<-c("Kansa","Kansa","Kansa","Kansa","Kansa","Kansa","Kansa","Kansa","Kansa","Kansa","Kentucky","Kentucky","Kentucky","Kentucky","Kentucky","Kentucky","Kentucky","Kentucky","Kentucky","Kentucky", "Texas", "Texas", "Texas", "Texas", "Texas", "Texas", "Texas", "Texas", "Texas", "Texas")
reg_results55<-lm(State_installation~state)
summary(reg_results55)
##
## Call:
## lm(formula = State_installation ~ state)
##
## Residuals:
## Min 1Q Median 3Q Max
## -299.80 -95.83 -37.90 153.32 295.20
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 279.60 53.43 5.233 1.63e-05 ***
## stateKentucky 80.30 75.56 1.063 0.2973
## stateTexas 198.20 75.56 2.623 0.0141 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 168.9 on 27 degrees of freedom
## Multiple R-squared: 0.205, Adjusted R-squared: 0.1462
## F-statistic: 3.482 on 2 and 27 DF, p-value: 0.04515
anova(reg_results55)
## Analysis of Variance Table
##
## Response: State_installation
## Df Sum Sq Mean Sq F value Pr(>F)
## state 2 198772 99386 3.4819 0.04515 *
## Residuals 27 770671 28543
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Performance <- c(65, 73, 68, 78,82, 48,46, 36, 50,43, 61,62)
Type<- c("F1", "F1","F1", "F2", "F2", "F3", "F3","F1", "F2", "F2", "F3", "F3")
Brand<-c("B1", "B1", "B1","B1","B1","B1","B1","B2","B2","B2","B2","B2")
reg_results510 <-lm(Performance ~Type+Brand)
summary(reg_results510)
##
## Call:
## lm(formula = Performance ~ Type + Brand)
##
## Residuals:
## Min 1Q Median 3Q Max
## -16.159 -12.415 2.046 9.119 15.659
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 64.455 7.180 8.976 1.89e-05 ***
## TypeF2 6.705 9.941 0.674 0.5190
## TypeF3 -2.295 9.941 -0.231 0.8232
## BrandB2 -15.818 8.291 -1.908 0.0928 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.75 on 8 degrees of freedom
## Multiple R-squared: 0.362, Adjusted R-squared: 0.1228
## F-statistic: 1.513 on 3 and 8 DF, p-value: 0.2838
anova(reg_results510)
## Analysis of Variance Table
##
## Response: Performance
## Df Sum Sq Mean Sq F value Pr(>F)
## Type 2 170.17 85.08 0.4501 0.65280
## Brand 1 688.09 688.09 3.6397 0.09285 .
## Residuals 8 1512.41 189.05
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
predict(reg_results510, se.fit=TRUE,interval="confidence")
## $fit
## fit lwr upr
## 1 64.45455 47.89631 81.01278
## 2 64.45455 47.89631 81.01278
## 3 64.45455 47.89631 81.01278
## 4 71.15909 52.64642 89.67176
## 5 71.15909 52.64642 89.67176
## 6 62.15909 43.64642 80.67176
## 7 62.15909 43.64642 80.67176
## 8 48.63636 27.25978 70.01295
## 9 55.34091 36.82824 73.85358
## 10 55.34091 36.82824 73.85358
## 11 46.34091 27.82824 64.85358
## 12 46.34091 27.82824 64.85358
##
## $se.fit
## [1] 7.180488 7.180488 7.180488 8.028029 8.028029 8.028029 8.028029 9.269970
## [9] 8.028029 8.028029 8.028029 8.028029
##
## $df
## [1] 8
##
## $residual.scale
## [1] 13.74959
reg_results510$residuals
## 1 2 3 4 5 6
## 0.5454545 8.5454545 3.5454545 6.8409091 10.8409091 -14.1590909
## 7 8 9 10 11 12
## -16.1590909 -12.6363636 -5.3409091 -12.3409091 14.6590909 15.6590909
reg_results510_interact <-lm(Performance ~Type+Brand+Type:Brand)
summary(reg_results510_interact)
##
## Call:
## lm(formula = Performance ~ Type + Brand + Type:Brand)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.667 -1.250 -0.250 1.250 4.333
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 68.6667 1.9389 35.416 3.38e-08 ***
## TypeF2 11.3333 3.0656 3.697 0.010126 *
## TypeF3 -21.6667 3.0656 -7.068 0.000402 ***
## BrandB2 -32.6667 3.8778 -8.424 0.000153 ***
## TypeF2:BrandB2 -0.8333 5.1298 -0.162 0.876285
## TypeF3:BrandB2 47.1667 5.1298 9.195 9.33e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.358 on 6 degrees of freedom
## Multiple R-squared: 0.9715, Adjusted R-squared: 0.9477
## F-statistic: 40.84 on 5 and 6 DF, p-value: 0.0001477
anova(reg_results510_interact)
## Analysis of Variance Table
##
## Response: Performance
## Df Sum Sq Mean Sq F value Pr(>F)
## Type 2 170.17 85.08 7.5443 0.0230306 *
## Brand 1 688.09 688.09 61.0130 0.0002323 ***
## Type:Brand 2 1444.74 722.37 64.0526 8.956e-05 ***
## Residuals 6 67.67 11.28
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
predict(reg_results510_interact, se.fit=TRUE, interval="confidence")
## $fit
## fit lwr upr
## 1 68.66667 63.92240 73.41094
## 2 68.66667 63.92240 73.41094
## 3 68.66667 63.92240 73.41094
## 4 80.00000 74.18948 85.81052
## 5 80.00000 74.18948 85.81052
## 6 47.00000 41.18948 52.81052
## 7 47.00000 41.18948 52.81052
## 8 36.00000 27.78268 44.21732
## 9 46.50000 40.68948 52.31052
## 10 46.50000 40.68948 52.31052
## 11 61.50000 55.68948 67.31052
## 12 61.50000 55.68948 67.31052
##
## $se.fit
## [1] 1.938881 1.938881 1.938881 2.374634 2.374634 2.374634 2.374634 3.358240
## [9] 2.374634 2.374634 2.374634 2.374634
##
## $df
## [1] 6
##
## $residual.scale
## [1] 3.35824
reg_results510_interact$residuals
## 1 2 3 4 5
## -3.666667e+00 4.333333e+00 -6.666667e-01 -2.000000e+00 2.000000e+00
## 6 7 8 9 10
## 1.000000e+00 -1.000000e+00 -9.992007e-16 3.500000e+00 -3.500000e+00
## 11 12
## -5.000000e-01 5.000000e-01