Project
library(carData)
library(car)
library(MASS)
library(MASS)
library(lmridge)
##
## Attaching package: 'lmridge'
## The following object is masked from 'package:car':
##
## vif
library(ALSM)
## Loading required package: leaps
## Loading required package: SuppDists
library(leaps)
library(caret)
## Loading required package: lattice
##
## Attaching package: 'lattice'
## The following object is masked from 'package:ALSM':
##
## oneway
## Loading required package: ggplot2
happiness<-read.table("/Users/yushanwang/desktop/2020fall/stat512/project/happiness_clean.csv", header =TRUE, sep=",")
colnames(happiness) <- c("ladder_score","gdp","support","health","freedom","generosity","corruption")
mod<-lm(ladder_score~gdp+support+health+freedom+generosity+corruption, happiness)
#part3
plot(happiness)

mod1<-lm(ladder_score~gdp,happiness)
plot(ladder_score~gdp,happiness)
abline(mod1)

mod2<-lm(ladder_score~support,happiness)
plot(ladder_score~support,happiness)
abline(mod2)

mod3<-lm(ladder_score~health,happiness)
plot(ladder_score~health,happiness)
abline(mod3)

mod4<-lm(ladder_score~freedom,happiness)
plot(ladder_score~freedom,happiness)
abline(mod4)

mod5<-lm(ladder_score~generosity,happiness)
plot(ladder_score~generosity,happiness)
abline(mod5)

mod6<-lm(ladder_score~corruption,happiness)
plot(ladder_score~corruption,happiness)
abline(mod6)

cor(happiness)
## ladder_score gdp support health freedom
## ladder_score 1.00000000 0.7753744 0.76500076 0.77031629 0.5905968
## gdp 0.77537440 1.0000000 0.78181358 0.84846862 0.4190186
## support 0.76500076 0.7818136 1.00000000 0.74274409 0.4788632
## health 0.77031629 0.8484686 0.74274409 1.00000000 0.4488462
## freedom 0.59059678 0.4190186 0.47886318 0.44884619 1.0000000
## generosity 0.06904313 -0.1183994 -0.05678035 -0.07185211 0.2537211
## corruption -0.41830509 -0.3347291 -0.21052960 -0.35384121 -0.4201445
## generosity corruption
## ladder_score 0.06904313 -0.4183051
## gdp -0.11839937 -0.3347291
## support -0.05678035 -0.2105296
## health -0.07185211 -0.3538412
## freedom 0.25372112 -0.4201445
## generosity 1.00000000 -0.2784802
## corruption -0.27848023 1.0000000
residualPlots(mod)

## Test stat Pr(>|Test stat|)
## gdp 3.3055 0.001195 **
## support 3.1246 0.002151 **
## health 2.9058 0.004239 **
## freedom -0.4288 0.668699
## generosity -2.7002 0.007755 **
## corruption -0.4993 0.618302
## Tukey test 4.3831 1.17e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#part4
#first order model
summary(mod)
##
## Call:
## lm(formula = ladder_score ~ gdp + support + health + freedom +
## generosity + corruption, data = happiness)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.75647 -0.31792 0.06653 0.37230 1.48375
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.05938 0.63984 -3.219 0.001588 **
## gdp 0.22908 0.08208 2.791 0.005960 **
## support 2.72332 0.66118 4.119 6.35e-05 ***
## health 0.03531 0.01297 2.721 0.007293 **
## freedom 1.77682 0.49752 3.571 0.000481 ***
## generosity 0.41057 0.33704 1.218 0.225126
## corruption -0.62816 0.31480 -1.995 0.047857 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5693 on 146 degrees of freedom
## Multiple R-squared: 0.7483, Adjusted R-squared: 0.738
## F-statistic: 72.36 on 6 and 146 DF, p-value: < 2.2e-16
#GLT
qf(0.95,6,146)
## [1] 2.161209
anova(mod)
## Analysis of Variance Table
##
## Response: ladder_score
## Df Sum Sq Mean Sq F value Pr(>F)
## gdp 1 113.054 113.054 348.7774 < 2.2e-16 ***
## support 1 12.198 12.198 37.6314 7.623e-09 ***
## health 1 4.561 4.561 14.0708 0.0002533 ***
## freedom 1 8.571 8.571 26.4407 8.597e-07 ***
## generosity 1 1.046 1.046 3.2281 0.0744513 .
## corruption 1 1.291 1.291 3.9817 0.0478570 *
## Residuals 146 47.325 0.324
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
avPlots(mod) # added-var plot

influencePlot(mod) # identify outlying y,x, and influential case

## StudRes Hat CookD
## 133 -2.369679 0.10816961 0.09431647
## 147 -3.283820 0.05821025 0.08923550
## 149 1.793773 0.14110157 0.07438410
## 150 -2.954493 0.15476192 0.21684525
qt(1-0.05/(2*153),153-1-7)
## [1] 3.681136
plot(mod,pch=18,which=c(4)) # cook's distance plot

cor(happiness) # correlation
## ladder_score gdp support health freedom
## ladder_score 1.00000000 0.7753744 0.76500076 0.77031629 0.5905968
## gdp 0.77537440 1.0000000 0.78181358 0.84846862 0.4190186
## support 0.76500076 0.7818136 1.00000000 0.74274409 0.4788632
## health 0.77031629 0.8484686 0.74274409 1.00000000 0.4488462
## freedom 0.59059678 0.4190186 0.47886318 0.44884619 1.0000000
## generosity 0.06904313 -0.1183994 -0.05678035 -0.07185211 0.2537211
## corruption -0.41830509 -0.3347291 -0.21052960 -0.35384121 -0.4201445
## generosity corruption
## ladder_score 0.06904313 -0.4183051
## gdp -0.11839937 -0.3347291
## support -0.05678035 -0.2105296
## health -0.07185211 -0.3538412
## freedom 0.25372112 -0.4201445
## generosity 1.00000000 -0.2784802
## corruption -0.27848023 1.0000000
vif<-lmridge(ladder_score~gdp+support+health+freedom+generosity+corruption, data=as.data.frame(happiness),
K=seq(0,0.22, 0.02)) #vif factors
vif(vif)
## gdp support health freedom generosity corruption
## k=0 4.56165 3.02382 3.93187 1.61034 1.22758 1.42596
## k=0.02 3.56557 2.57170 3.17218 1.48779 1.15652 1.32281
## k=0.04 2.87336 2.22045 2.62553 1.38089 1.09270 1.23370
## k=0.06 2.37218 1.94120 2.21724 1.28663 1.03495 1.15561
## k=0.08 1.99720 1.71498 1.90315 1.20281 0.98238 1.08640
## k=0.1 1.70900 1.52880 1.65568 1.12778 0.93432 1.02451
## k=0.12 1.48246 1.37351 1.45679 1.06023 0.89018 0.96875
## k=0.14 1.30098 1.24246 1.29425 0.99910 0.84950 0.91820
## k=0.16 1.15321 1.13074 1.15949 0.94356 0.81190 0.87212
## k=0.18 1.03117 1.03463 1.04638 0.89290 0.77703 0.82993
## k=0.2 0.92912 0.95128 0.95041 0.84652 0.74462 0.79114
## k=0.22 0.84285 0.87847 0.86819 0.80393 0.71442 0.75535
summary(vif)
##
## Call:
## lmridge.default(formula = ladder_score ~ gdp + support + health +
## freedom + generosity + corruption, data = as.data.frame(happiness),
## K = seq(0, 0.22, 0.02))
##
##
## Coefficients: for Ridge parameter K= 0
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -2.0594 -228.3776 73.3850 -3.1120 0.0022 **
## gdp 0.2291 3.3936 1.2118 2.8004 0.0058 **
## support 2.7233 4.0778 0.9867 4.1330 0.0001 ***
## health 0.0353 3.0722 1.1251 2.7307 0.0071 **
## freedom 1.7768 2.5802 0.7200 3.5835 0.0005 ***
## generosity 0.4106 0.7684 0.6287 1.2223 0.2236
## corruption -0.6282 -1.3566 0.6775 -2.0022 0.0471 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.74830 0.73980 5.99999 72.85062 -167.52975 620.30985
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 5.99999 , 147 ) = 1.452181e-41
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.02
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -2.0115 -228.6770 65.8914 -3.4705 0.0007 ***
## gdp 0.2277 3.3733 1.0714 3.1485 0.0020 **
## support 2.6787 4.0110 0.9099 4.4082 <2e-16 ***
## health 0.0354 3.0808 1.0106 3.0486 0.0027 **
## freedom 1.7698 2.5701 0.6921 3.7136 0.0003 ***
## generosity 0.4009 0.7504 0.6102 1.2298 0.2208
## corruption -0.6282 -1.3566 0.6526 -2.0789 0.0394 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.73850 0.72960 5.71072 72.85162 -168.08566 618.87732
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 5.71072 , 147.0238 ) = 1.32947e-40
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.04
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.9631 -228.6911 59.9301 -3.8160 0.0002 ***
## gdp 0.2264 3.3533 0.9618 3.4864 0.0006 ***
## support 2.6380 3.9501 0.8455 4.6719 <2e-16 ***
## health 0.0355 3.0848 0.9194 3.3552 0.0010 ***
## freedom 1.7623 2.5591 0.6668 3.8380 0.0002 ***
## generosity 0.3918 0.7332 0.5931 1.2362 0.2184
## corruption -0.6283 -1.3570 0.6302 -2.1531 0.0329 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.72890 0.71970 5.46470 72.84742 -168.51234 617.70509
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 5.4647 , 147.0781 ) = 9.374532e-40
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.06
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.9145 -228.4870 55.0660 -4.1493 0.0001 ***
## gdp 0.2250 3.3336 0.8740 3.8141 0.0002 ***
## support 2.6006 3.8940 0.7906 4.9252 <2e-16 ***
## health 0.0355 3.0853 0.8450 3.6513 0.0004 ***
## freedom 1.7542 2.5474 0.6437 3.9576 0.0001 ***
## generosity 0.3830 0.7169 0.5773 1.2418 0.2163
## corruption -0.6286 -1.3575 0.6100 -2.2253 0.0276 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.71950 0.71000 5.25089 72.83237 -168.83507 616.73443
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 5.25089 , 147.1486 ) = 5.45214e-39
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.08
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.8659 -228.1132 51.0168 -4.4713 <2e-16 ***
## gdp 0.2237 3.3141 0.8021 4.1316 0.0001 ***
## support 2.5659 3.8420 0.7433 5.1690 <2e-16 ***
## health 0.0354 3.0831 0.7830 3.9375 0.0001 ***
## freedom 1.7458 2.5352 0.6225 4.0728 0.0001 ***
## generosity 0.3747 0.7013 0.5626 1.2467 0.2145
## corruption -0.6288 -1.3580 0.5916 -2.2955 0.0231 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.71030 0.70050 5.06226 72.80360 -169.07055 615.92731
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 5.06226 , 147.2268 ) = 2.728976e-38
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.1
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.8176 -227.6054 47.5908 -4.7825 <2e-16 ***
## gdp 0.2224 3.2947 0.7422 4.4390 <2e-16 ***
## support 2.5334 3.7935 0.7020 5.4039 <2e-16 ***
## health 0.0354 3.0788 0.7305 4.2144 <2e-16 ***
## freedom 1.7372 2.5227 0.6029 4.1840 <2e-16 ***
## generosity 0.3668 0.6865 0.5488 1.2509 0.2129
## corruption -0.6290 -1.3584 0.5747 -2.3639 0.0194 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.70130 0.69120 4.89399 72.75978 -169.23070 615.25724
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.89399 , 147.308 ) = 1.209401e-37
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.12
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.7695 -226.9909 44.6527 -5.0835 <2e-16 ***
## gdp 0.2211 3.2755 0.6916 4.7365 <2e-16 ***
## support 2.5029 3.7479 0.6657 5.6303 <2e-16 ***
## health 0.0353 3.0727 0.6855 4.4822 <2e-16 ***
## freedom 1.7283 2.5098 0.5848 4.2915 <2e-16 ***
## generosity 0.3592 0.6723 0.5359 1.2546 0.2116
## corruption -0.6291 -1.3587 0.5590 -2.4305 0.0163 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.69250 0.68200 4.74213 72.70092 -169.32541 614.70233
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.74213 , 147.39 ) = 4.859304e-37
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.14
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.7218 -226.2905 42.1043 -5.3745 <2e-16 ***
## gdp 0.2198 3.2565 0.6482 5.0241 <2e-16 ***
## support 2.4742 3.7048 0.6334 5.8488 <2e-16 ***
## health 0.0352 3.0653 0.6465 4.7415 <2e-16 ***
## freedom 1.7193 2.4968 0.5680 4.3956 <2e-16 ***
## generosity 0.3520 0.6588 0.5238 1.2579 0.2104
## corruption -0.6292 -1.3589 0.5445 -2.4955 0.0137 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.68390 0.67310 4.60386 72.62721 -169.36213 614.24658
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.60386 , 147.4715 ) = 1.800014e-36
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.16
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.6745 -225.5206 39.8724 -5.6561 <2e-16 ***
## gdp 0.2186 3.2376 0.6106 5.3021 <2e-16 ***
## support 2.4469 3.6640 0.6046 6.0597 <2e-16 ***
## health 0.0351 3.0568 0.6123 4.9924 <2e-16 ***
## freedom 1.7102 2.4835 0.5523 4.4964 <2e-16 ***
## generosity 0.3451 0.6459 0.5124 1.2607 0.2094
## corruption -0.6292 -1.3588 0.5310 -2.5588 0.0115 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.67540 0.66430 4.47730 72.53887 -169.34629 613.87889
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.4773 , 147.5513 ) = 6.210931e-36
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.18
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.6278 -224.6944 37.9012 -5.9284 <2e-16 ***
## gdp 0.2173 3.2188 0.5778 5.5707 <2e-16 ***
## support 2.4210 3.6251 0.5788 6.2633 <2e-16 ***
## health 0.0350 3.0473 0.5821 5.2353 <2e-16 ***
## freedom 1.7011 2.4702 0.5377 4.5942 <2e-16 ***
## generosity 0.3385 0.6336 0.5016 1.2631 0.2085
## corruption -0.6290 -1.3585 0.5184 -2.6207 0.0097 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.66710 0.65570 4.36052 72.43668 -169.28329 613.58800
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.36052 , 147.6293 ) = 2.020045e-35
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.2
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.5816 -223.8221 36.1474 -6.1919 <2e-16 ***
## gdp 0.2160 3.2002 0.5489 5.8301 <2e-16 ***
## support 2.3962 3.5880 0.5554 6.4599 <2e-16 ***
## health 0.0349 3.0371 0.5552 5.4705 <2e-16 ***
## freedom 1.6919 2.4569 0.5239 4.6891 <2e-16 ***
## generosity 0.3322 0.6218 0.4914 1.2653 0.2078
## corruption -0.6288 -1.3580 0.5065 -2.6810 0.0082 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.65890 0.64730 4.25236 72.32113 -169.17687 613.36665
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.25236 , 147.7051 ) = 6.231208e-35
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.22
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -1.5359 -222.9124 34.5770 -6.4468 <2e-16 ***
## gdp 0.2148 3.1818 0.5233 6.0805 <2e-16 ***
## support 2.3725 3.5525 0.5342 6.6498 <2e-16 ***
## health 0.0348 3.0262 0.5311 5.6982 <2e-16 ***
## freedom 1.6826 2.4435 0.5111 4.7813 <2e-16 ***
## generosity 0.3262 0.6104 0.4818 1.2671 0.2071
## corruption -0.6285 -1.3573 0.4954 -2.7399 0.0069 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.65090 0.63900 4.15169 72.19286 -169.03066 613.20778
## Ridge minimum MSE= 1.946592 at K= 0.22
## P-value for F-test ( 4.15169 , 147.7784 ) = 1.835158e-34
## -------------------------------------------------------------------
bs<-BestSub(happiness[,2:7],happiness$ladder_score,num=1) # best subset
bs
## p 1 2 3 4 5 6 SSEp r2 r2.adj Cp AICp SBCp
## 1 2 1 0 0 0 0 0 74.99173 0.6012055 0.5985644 82.352712 -105.0982 -99.03732
## 2 3 1 0 0 1 0 0 58.88904 0.6868371 0.6826616 34.675218 -140.0818 -130.99048
## 3 4 0 1 1 1 0 0 52.54787 0.7205585 0.7149321 17.112440 -155.5131 -143.39139
## 4 5 1 1 1 1 0 0 49.66214 0.7359043 0.7287666 10.209843 -162.1548 -147.00265
## 5 6 1 1 1 1 0 1 47.80612 0.7457744 0.7371273 6.483929 -165.9825 -147.79987
## 6 7 1 1 1 1 1 1 47.32511 0.7483323 0.7379898 7.000000 -165.5297 -144.31666
## PRESSp
## 1 76.91505
## 2 61.09347
## 3 56.02698
## 4 53.56514
## 5 52.77714
## 6 53.15361
#Consider the Model with Higher Order
happiness.mod.high_order.f <- lm(ladder_score ~ gdp + support + health + freedom + corruption + gdp*support + gdp*health + support*health, happiness)
happiness.mod.high_order.r <- lm(ladder_score ~ gdp + support + health + freedom + corruption, happiness)
anova(happiness.mod.high_order.r, happiness.mod.high_order.f)
## Analysis of Variance Table
##
## Model 1: ladder_score ~ gdp + support + health + freedom + corruption
## Model 2: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * support + gdp * health + support * health
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 147 47.806
## 2 144 40.319 3 7.4875 8.914 1.86e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
happiness.mod.high_order.r1 <- lm(ladder_score ~ gdp + support + health + freedom + corruption + gdp*health + support*health, happiness)
anova(happiness.mod.high_order.r1, happiness.mod.high_order.f)
## Analysis of Variance Table
##
## Model 1: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * health + support * health
## Model 2: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * support + gdp * health + support * health
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 145 40.319
## 2 144 40.319 1 0.00075651 0.0027 0.9586
happiness.mod.high_order.r2 <- lm(ladder_score ~ gdp + support + health + freedom + corruption + gdp*support + support*health, happiness)
anova(happiness.mod.high_order.r2, happiness.mod.high_order.f)
## Analysis of Variance Table
##
## Model 1: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * support + support * health
## Model 2: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * support + gdp * health + support * health
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 145 40.377
## 2 144 40.319 1 0.058729 0.2098 0.6477
happiness.mod.high_order.r3 <- lm(ladder_score ~ gdp + support + health + freedom + corruption + gdp*support + gdp*health, happiness)
anova(happiness.mod.high_order.r3, happiness.mod.high_order.f)
## Analysis of Variance Table
##
## Model 1: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * support + gdp * health
## Model 2: ladder_score ~ gdp + support + health + freedom + corruption +
## gdp * support + gdp * health + support * health
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 145 41.506
## 2 144 40.319 1 1.1874 4.241 0.04126 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
happiness.mod.high_order<-lm(ladder_score ~ gdp + support + health + freedom + corruption + support*health, happiness)
residualPlots(happiness.mod.high_order)

## Test stat Pr(>|Test stat|)
## gdp 0.9734 0.33199
## support -1.7356 0.08475 .
## health -0.3888 0.69800
## freedom -1.2228 0.22341
## corruption -1.2960 0.19703
## Tukey test 1.2666 0.20529
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qqPlot(happiness$ladder_score)

## [1] 153 152
Anova(happiness.mod.high_order.f, type = "II")
## Anova Table (Type II tests)
##
## Response: ladder_score
## Sum Sq Df F value Pr(>F)
## gdp 1.343 1 4.7964 0.030129 *
## support 7.596 1 27.1298 6.457e-07 ***
## health 2.771 1 9.8981 0.002011 **
## freedom 5.798 1 20.7090 1.127e-05 ***
## corruption 0.122 1 0.4365 0.509863
## gdp:support 0.001 1 0.0027 0.958617
## gdp:health 0.059 1 0.2098 0.647651
## support:health 1.187 1 4.2410 0.041259 *
## Residuals 40.319 144
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
avPlots(happiness.mod.high_order.f)

happiness_new <- happiness[,c(1,2,3,4,5,7)]
happiness_new <- cbind(happiness_new, happiness$gdp * happiness$support, happiness$gdp * happiness$health, happiness$support * happiness$health)
plot(happiness.mod.high_order.f)




BestSub(happiness_new[,2:9], happiness_new$ladder_score, num = 1)
## p 1 2 3 4 5 6 7 8 SSEp r2 r2.adj Cp AICp SBCp
## 1 2 0 0 0 0 0 0 0 1 56.30861 0.7005594 0.6985764 52.109203 -148.9373 -142.8765
## 2 3 0 0 0 1 0 0 0 1 48.90272 0.7399428 0.7364754 27.658680 -168.5125 -159.4212
## 3 4 0 0 0 1 0 0 1 1 46.71083 0.7515990 0.7465976 21.830226 -173.5287 -161.4069
## 4 5 0 1 1 1 0 0 0 1 42.08466 0.7762002 0.7701516 7.307599 -187.4855 -172.3333
## 5 6 0 1 1 1 0 0 1 1 40.51170 0.7845650 0.7772373 3.689700 -191.3136 -173.1310
## 6 7 0 1 1 1 1 0 1 1 40.32960 0.7855334 0.7767197 5.039314 -190.0029 -168.7898
## 7 8 1 1 1 1 1 0 1 1 40.31935 0.7855879 0.7752370 7.002702 -188.0418 -163.7983
## 8 9 1 1 1 1 1 1 1 1 40.31859 0.7855919 0.7736803 9.000000 -186.0447 -158.7707
## PRESSp
## 1 58.13894
## 2 51.05517
## 3 49.47846
## 4 46.55470
## 5 45.45225
## 6 46.13982
## 7 47.16947
## 8 48.11769
influencePlot(happiness.mod.high_order.f)

## StudRes Hat CookD
## 86 2.498296 0.10343972 0.07720153
## 147 -3.249935 0.05629888 0.06565240
## 149 -1.918434 0.55043016 0.49152624
## 150 -2.378420 0.25630676 0.20983520
qt(0.9998,143)
## [1] 3.625646
plot(happiness.mod.high_order.f, which = c(4))

vif.high <- lmridge(ladder_score ~ gdp + support + health + freedom + corruption + gdp*support + gdp*health + support*health, happiness, K=seq(0,1, 0.02))
vif.high
## Call:
## lmridge.default(formula = ladder_score ~ gdp + support + health +
## freedom + corruption + gdp * support + gdp * health + support *
## health, data = happiness, K = seq(0, 1, 0.02))
##
## Intercept gdp support health freedom corruption gdp:support
## K=0 11.19092 -0.13699 -11.36858 -0.18580 2.08058 -0.21486 0.03565
## K=0.02 1.90243 -0.06683 -0.96000 -0.00961 1.91061 -0.55329 0.19077
## K=0.04 0.90544 0.00345 0.06786 0.00236 1.86636 -0.59421 0.14145
## K=0.06 0.53541 0.03127 0.45413 0.00694 1.83333 -0.60715 0.12195
## K=0.08 0.34954 0.04634 0.65261 0.00937 1.80429 -0.61192 0.11144
## K=0.1 0.24247 0.05588 0.77113 0.01089 1.77750 -0.61324 0.10481
## K=0.12 0.17626 0.06250 0.84843 0.01192 1.75230 -0.61281 0.10023
## K=0.14 0.13393 0.06738 0.90180 0.01267 1.72836 -0.61139 0.09684
## K=0.16 0.10671 0.07113 0.94014 0.01324 1.70551 -0.60936 0.09421
## K=0.18 0.08963 0.07412 0.96845 0.01369 1.68361 -0.60693 0.09210
## K=0.2 0.07967 0.07655 0.98978 0.01405 1.66258 -0.60425 0.09036
## K=0.22 0.07486 0.07856 1.00608 0.01435 1.64235 -0.60139 0.08889
## K=0.24 0.07391 0.08025 1.01864 0.01459 1.62286 -0.59841 0.08762
## K=0.26 0.07590 0.08170 1.02837 0.01480 1.60406 -0.59535 0.08652
## K=0.28 0.08016 0.08294 1.03590 0.01497 1.58590 -0.59224 0.08553
## K=0.3 0.08623 0.08401 1.04170 0.01513 1.56835 -0.58909 0.08465
## K=0.32 0.09373 0.08495 1.04613 0.01525 1.55137 -0.58593 0.08386
## K=0.34 0.10238 0.08577 1.04945 0.01537 1.53493 -0.58275 0.08313
## K=0.36 0.11198 0.08649 1.05186 0.01546 1.51901 -0.57958 0.08246
## K=0.38 0.12235 0.08712 1.05352 0.01555 1.50356 -0.57642 0.08184
## K=0.4 0.13336 0.08769 1.05457 0.01562 1.48857 -0.57328 0.08125
## K=0.42 0.14490 0.08819 1.05509 0.01568 1.47402 -0.57015 0.08071
## K=0.44 0.15687 0.08863 1.05518 0.01574 1.45989 -0.56704 0.08020
## K=0.46 0.16921 0.08902 1.05490 0.01579 1.44614 -0.56396 0.07971
## K=0.48 0.18185 0.08937 1.05431 0.01583 1.43278 -0.56090 0.07925
## K=0.5 0.19474 0.08968 1.05344 0.01586 1.41977 -0.55787 0.07881
## K=0.52 0.20785 0.08995 1.05235 0.01589 1.40711 -0.55487 0.07839
## K=0.54 0.22113 0.09019 1.05106 0.01592 1.39477 -0.55189 0.07798
## K=0.56 0.23455 0.09040 1.04959 0.01594 1.38275 -0.54895 0.07759
## K=0.58 0.24810 0.09059 1.04798 0.01596 1.37102 -0.54604 0.07722
## K=0.6 0.26174 0.09075 1.04624 0.01597 1.35958 -0.54316 0.07686
## K=0.62 0.27545 0.09089 1.04439 0.01598 1.34842 -0.54031 0.07650
## K=0.64 0.28923 0.09100 1.04244 0.01599 1.33752 -0.53749 0.07616
## K=0.66 0.30305 0.09110 1.04040 0.01600 1.32687 -0.53470 0.07583
## K=0.68 0.31691 0.09119 1.03829 0.01600 1.31647 -0.53195 0.07551
## K=0.7 0.33079 0.09125 1.03612 0.01600 1.30630 -0.52922 0.07519
## K=0.72 0.34468 0.09130 1.03389 0.01600 1.29636 -0.52653 0.07489
## K=0.74 0.35857 0.09134 1.03161 0.01599 1.28663 -0.52387 0.07459
## K=0.76 0.37247 0.09137 1.02929 0.01599 1.27711 -0.52123 0.07429
## K=0.78 0.38635 0.09138 1.02693 0.01598 1.26779 -0.51863 0.07400
## K=0.8 0.40022 0.09139 1.02453 0.01597 1.25867 -0.51606 0.07372
## K=0.82 0.41407 0.09138 1.02211 0.01596 1.24973 -0.51351 0.07345
## K=0.84 0.42789 0.09136 1.01967 0.01595 1.24097 -0.51100 0.07317
## K=0.86 0.44168 0.09134 1.01720 0.01594 1.23238 -0.50851 0.07291
## K=0.88 0.45545 0.09130 1.01472 0.01592 1.22396 -0.50605 0.07264
## K=0.9 0.46917 0.09126 1.01222 0.01591 1.21571 -0.50362 0.07239
## K=0.92 0.48286 0.09121 1.00971 0.01589 1.20761 -0.50122 0.07213
## K=0.94 0.49651 0.09116 1.00719 0.01588 1.19966 -0.49884 0.07188
## K=0.96 0.51011 0.09110 1.00467 0.01586 1.19186 -0.49650 0.07163
## K=0.98 0.52368 0.09103 1.00213 0.01584 1.18420 -0.49417 0.07139
## K=1 0.53719 0.09096 0.99959 0.01582 1.17668 -0.49188 0.07115
## gdp:health support:health
## K=0 0.00434 0.23409
## K=0.02 0.00181 0.03680
## K=0.04 0.00140 0.02603
## K=0.06 0.00125 0.02190
## K=0.08 0.00117 0.01969
## K=0.1 0.00112 0.01831
## K=0.12 0.00109 0.01735
## K=0.14 0.00106 0.01664
## K=0.16 0.00105 0.01609
## K=0.18 0.00103 0.01566
## K=0.2 0.00102 0.01529
## K=0.22 0.00101 0.01499
## K=0.24 0.00101 0.01473
## K=0.26 0.00100 0.01450
## K=0.28 0.00100 0.01429
## K=0.3 0.00099 0.01411
## K=0.32 0.00099 0.01395
## K=0.34 0.00098 0.01380
## K=0.36 0.00098 0.01367
## K=0.38 0.00098 0.01354
## K=0.4 0.00098 0.01342
## K=0.42 0.00097 0.01331
## K=0.44 0.00097 0.01321
## K=0.46 0.00097 0.01312
## K=0.48 0.00096 0.01302
## K=0.5 0.00096 0.01294
## K=0.52 0.00096 0.01286
## K=0.54 0.00096 0.01278
## K=0.56 0.00096 0.01270
## K=0.58 0.00095 0.01263
## K=0.6 0.00095 0.01256
## K=0.62 0.00095 0.01249
## K=0.64 0.00095 0.01243
## K=0.66 0.00095 0.01236
## K=0.68 0.00094 0.01230
## K=0.7 0.00094 0.01224
## K=0.72 0.00094 0.01218
## K=0.74 0.00094 0.01213
## K=0.76 0.00093 0.01207
## K=0.78 0.00093 0.01202
## K=0.8 0.00093 0.01197
## K=0.82 0.00093 0.01192
## K=0.84 0.00093 0.01187
## K=0.86 0.00092 0.01182
## K=0.88 0.00092 0.01177
## K=0.9 0.00092 0.01172
## K=0.92 0.00092 0.01168
## K=0.94 0.00092 0.01163
## K=0.96 0.00091 0.01159
## K=0.98 0.00091 0.01154
## K=1 0.00091 0.01150
# summary(vif.high)
vif.final <- lmridge(ladder_score ~ gdp + support + health + freedom + corruption + gdp*support + gdp*health + support*health, happiness, K=0)
summary(vif.final)
##
## Call:
## lmridge.default(formula = ladder_score ~ gdp + support + health +
## freedom + corruption + gdp * support + gdp * health + support *
## health, data = happiness, K = 0)
##
##
## Coefficients: for Ridge parameter K= 0
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept 11.1909 -5143.4478 9562.5667 -0.5379 0.5915
## gdp -0.1370 -2.0294 10.9542 -0.1853 0.8533
## support -11.3686 -17.0230 7.2128 -2.3601 0.0196 *
## health -0.1858 -16.1676 8.6207 -1.8754 0.0628 .
## freedom 2.0806 3.0213 0.6616 4.5665 <2e-16 ***
## corruption -0.2149 -0.4640 0.6999 -0.6630 0.5084
## gdp:support 0.0356 0.8347 16.0028 0.0522 0.9585
## gdp:health 0.0043 7.2044 15.6762 0.4596 0.6465
## support:health 0.2341 35.0264 16.9495 2.0665 0.0406 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.78560 0.77520 8.00004 66.41003 -188.04458 605.85604
## Ridge minimum MSE= 1036.379 at K= 0
## P-value for F-test ( 8.00004 , 144.9999 ) = 1.105563e-44
## -------------------------------------------------------------------
#Repeat diagnostic and remedy analysis
avPlots(happiness.mod.high_order)

influencePlot(happiness.mod.high_order)

## StudRes Hat CookD
## 130 -2.480368 0.01821279 0.01574823
## 147 -3.303957 0.04555014 0.06968978
## 149 -1.982876 0.52177325 0.60076746
## 150 -2.335985 0.17604012 0.16161758
plot(happiness.mod.high_order,pch=18,which=c(4))

vif.new<-lmridge(ladder_score ~ gdp + support + health + freedom + corruption + support*health,data=as.data.frame(happiness),
K=seq(0,0.2, 0.02)) #vif factors
summary(vif.new)
##
## Call:
## lmridge.default(formula = ladder_score ~ gdp + support + health +
## freedom + corruption + support * health, data = as.data.frame(happiness),
## K = seq(0, 0.2, 0.02))
##
##
## Coefficients: for Ridge parameter K= 0
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept 10.0944 -1139.6177 465.4634 -2.4484 0.0155 *
## gdp 0.1663 2.4638 1.1143 2.2110 0.0286 *
## support -13.0314 -19.5130 4.6339 -4.2110 <2e-16 ***
## health -0.1713 -14.9059 3.6011 -4.1392 0.0001 ***
## freedom 2.0420 2.9653 0.6466 4.5858 <2e-16 ***
## corruption -0.2746 -0.5931 0.6331 -0.9368 0.3504
## support:health 0.2656 39.7471 7.6459 5.1985 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.78530 0.77790 6.00002 89.58765 -191.80287 596.03682
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 6.00002 , 147 ) = 1.376836e-46
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.02
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept 0.3399 -403.5115 89.4859 -4.5092 <2e-16 ***
## gdp 0.1870 2.7708 1.0500 2.6388 0.0092 **
## support -0.1372 -0.2055 0.9796 -0.2098 0.8341
## health -0.0020 -0.1728 1.0287 -0.1680 0.8669
## freedom 1.8874 2.7408 0.6571 4.1711 0.0001 ***
## corruption -0.6467 -1.3967 0.6167 -2.2648 0.0250 *
## support:health 0.0498 7.4578 1.1242 6.6341 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.74360 0.73490 4.88570 80.28068 -176.44427 608.01854
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 4.8857 , 147.7753 ) = 6.592784e-40
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.04
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.3106 -353.5612 67.4000 -5.2457 <2e-16 ***
## gdp 0.1854 2.7465 0.9581 2.8666 0.0048 **
## support 0.7510 1.1246 0.7830 1.4362 0.1531
## health 0.0102 0.8884 0.8776 1.0123 0.3131
## freedom 1.8549 2.6935 0.6396 4.2113 <2e-16 ***
## corruption -0.6699 -1.4469 0.6015 -2.4055 0.0174 *
## support:health 0.0348 5.1997 0.6739 7.7161 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.73570 0.72670 4.61589 79.09846 -174.55322 609.09195
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 4.61589 , 147.9308 ) = 1.761888e-38
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.06
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.5268 -335.8923 58.6449 -5.7276 <2e-16 ***
## gdp 0.1832 2.7139 0.8789 3.0876 0.0024 **
## support 1.0669 1.5975 0.7039 2.2696 0.0247 *
## health 0.0148 1.2899 0.7960 1.6204 0.1073
## freedom 1.8293 2.6564 0.6208 4.2790 <2e-16 ***
## corruption -0.6764 -1.4609 0.5853 -2.4960 0.0137 *
## support:health 0.0292 4.3736 0.5157 8.4807 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.72820 0.71900 4.41213 78.65146 -173.98829 609.03940
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 4.41213 , 148.0327 ) = 1.69542e-37
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.08
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6229 -326.9223 53.1586 -6.1499 <2e-16 ***
## gdp 0.1811 2.6826 0.8119 3.3040 0.0012 **
## support 1.2246 1.8336 0.6520 2.8122 0.0056 **
## health 0.0173 1.5049 0.7348 2.0481 0.0423 *
## freedom 1.8063 2.6231 0.6027 4.3523 <2e-16 ***
## corruption -0.6783 -1.4649 0.5698 -2.5710 0.0111 *
## support:health 0.0263 3.9433 0.4347 9.0705 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.72090 0.71140 4.24072 78.40740 -173.76348 608.74476
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 4.24072 , 148.1218 ) = 1.101579e-36
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.1
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6692 -321.4436 49.0744 -6.5501 <2e-16 ***
## gdp 0.1791 2.6539 0.7548 3.5161 0.0006 ***
## support 1.3166 1.9714 0.6117 3.2229 0.0016 **
## health 0.0188 1.6401 0.6847 2.3956 0.0178 *
## freedom 1.7850 2.5921 0.5856 4.4266 <2e-16 ***
## corruption -0.6782 -1.4646 0.5551 -2.6384 0.0092 **
## support:health 0.0246 3.6776 0.3846 9.5618 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.71380 0.70410 4.09114 78.24305 -173.65496 608.39999
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 4.09114 , 148.2057 ) = 5.699512e-36
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.12
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6901 -317.6684 45.7915 -6.9373 <2e-16 ***
## gdp 0.1774 2.6277 0.7056 3.7240 0.0003 ***
## support 1.3752 2.0591 0.5781 3.5622 0.0005 ***
## health 0.0199 1.7332 0.6422 2.6991 0.0078 **
## freedom 1.7648 2.5628 0.5695 4.5003 <2e-16 ***
## corruption -0.6770 -1.4622 0.5414 -2.7009 0.0077 **
## support:health 0.0234 3.4960 0.3499 9.9920 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.70680 0.69680 3.95814 78.11460 -173.58666 608.06524
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 3.95814 , 148.2861 ) = 2.516261e-35
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.14
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6964 -314.8282 43.0441 -7.3141 <2e-16 ***
## gdp 0.1758 2.6037 0.6629 3.9278 0.0001 ***
## support 1.4145 2.1181 0.5490 3.8579 0.0002 ***
## health 0.0207 1.8011 0.6054 2.9751 0.0034 **
## freedom 1.7456 2.5350 0.5544 4.5728 <2e-16 ***
## corruption -0.6753 -1.4584 0.5284 -2.7599 0.0065 **
## support:health 0.0225 3.3629 0.3240 10.3799 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.69990 0.68970 3.83828 78.00281 -173.52739 607.76129
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 3.83828 , 148.3635 ) = 9.856406e-35
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.16
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6938 -312.5432 40.6883 -7.6814 <2e-16 ***
## gdp 0.1743 2.5815 0.6254 4.1276 0.0001 ***
## support 1.4419 2.1590 0.5235 4.1244 0.0001 ***
## health 0.0213 1.8525 0.5732 3.2319 0.0015 **
## freedom 1.7273 2.5083 0.5401 4.6438 <2e-16 ***
## corruption -0.6732 -1.4539 0.5163 -2.8161 0.0055 **
## support:health 0.0218 3.2603 0.3037 10.7358 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.69310 0.68270 3.72940 77.89777 -173.46230 607.49641
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 3.7294 , 148.4379 ) = 3.502559e-34
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.18
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6851 -310.6074 38.6350 -8.0395 <2e-16 ***
## gdp 0.1729 2.5610 0.5924 4.3233 <2e-16 ***
## support 1.4612 2.1879 0.5007 4.3699 <2e-16 ***
## health 0.0217 1.8925 0.5447 3.4744 0.0007 ***
## freedom 1.7097 2.4828 0.5268 4.7134 <2e-16 ***
## corruption -0.6709 -1.4489 0.5048 -2.8700 0.0047 **
## support:health 0.0212 3.1783 0.2872 11.0654 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.68640 0.67580 3.62962 77.79425 -173.38462 607.27172
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 3.62962 , 148.5095 ) = 1.149789e-33
## -------------------------------------------------------------------
##
##
## Coefficients: for Ridge parameter K= 0.2
## Estimate Estimate (Sc) StdErr (Sc) t-value (Sc) Pr(>|t|)
## Intercept -0.6723 -308.9008 36.8235 -8.3887 <2e-16 ***
## gdp 0.1716 2.5417 0.5630 4.5149 <2e-16 ***
## support 1.4749 2.2085 0.4802 4.5993 <2e-16 ***
## health 0.0221 1.9242 0.5193 3.7055 3e-04 ***
## freedom 1.6928 2.4582 0.5141 4.7814 <2e-16 ***
## corruption -0.6684 -1.4434 0.4940 -2.9218 4e-03 **
## support:health 0.0208 3.1106 0.2735 11.3727 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Ridge Summary
## R2 adj-R2 DF ridge F AIC BIC
## 0.67980 0.66900 3.53769 77.68907 -173.29069 607.08707
## Ridge minimum MSE= 94.9615 at K= 0
## P-value for F-test ( 3.53769 , 148.5782 ) = 3.526251e-33
## -------------------------------------------------------------------
happiness.mod.high_order.final <- lm(ladder_score ~ gdp + support + health + freedom + gdp*health + support*health, happiness)
anova(happiness.mod.high_order.final)
## Analysis of Variance Table
##
## Response: ladder_score
## Df Sum Sq Mean Sq F value Pr(>F)
## gdp 1 113.054 113.054 408.0548 < 2.2e-16 ***
## support 1 12.198 12.198 44.0271 5.909e-10 ***
## health 1 4.561 4.561 16.4622 8.054e-05 ***
## freedom 1 8.571 8.571 30.9345 1.237e-07 ***
## gdp:health 1 6.624 6.624 23.9092 2.633e-06 ***
## support:health 1 2.588 2.588 9.3399 0.002667 **
## Residuals 146 40.450 0.277
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(happiness.mod.high_order.final)
##
## Call:
## lm(formula = ladder_score ~ gdp + support + health + freedom +
## gdp * health + support * health, data = happiness)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.60953 -0.26613 0.05751 0.32877 1.23278
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11.994736 3.143390 3.816 0.000200 ***
## gdp -0.260425 0.553072 -0.471 0.638436
## support -11.065022 4.723072 -2.343 0.020492 *
## health -0.206716 0.051749 -3.995 0.000102 ***
## freedom 2.201834 0.419407 5.250 5.27e-07 ***
## gdp:health 0.006807 0.008610 0.791 0.430474
## support:health 0.233520 0.076411 3.056 0.002667 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5264 on 146 degrees of freedom
## Multiple R-squared: 0.7849, Adjusted R-squared: 0.7761
## F-statistic: 88.79 on 6 and 146 DF, p-value: < 2.2e-16