getwd()
## [1] "C:/data"
setwd('c:/data')
library(dplyr)
## Warning: 패키지 'dplyr'는 R 버전 4.2.3에서 작성되었습니다
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# 32p

Data1<-read.delim("Data1.txt")
nrow(Data1) # 행의 수
## [1] 1925
names(Data1) # 변수명
##  [1] "Q1"        "Q2"        "Q3"        "Q4"        "Q5"        "Q6"       
##  [7] "Q7"        "Q8"        "Q9"        "Q10"       "Q11"       "Q12"      
## [13] "Q13"       "Q14"       "Q15"       "Q16"       "Q17"       "Q18"      
## [19] "Q19"       "Q20"       "Gender"    "EDU"       "BF"        "BM"       
## [25] "Happiness" "Peace"
# 33p
data1<-Data1 %>% select(21:26)

# 결측값 확인
colSums(is.na(data1))
##    Gender       EDU        BF        BM Happiness     Peace 
##         0         0         0         0         0         0
# 데이터 유형
glimpse(data1)
## Rows: 1,925
## Columns: 6
## $ Gender    <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU       <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
# int -> fct로 변경
data1$Gender<-as.factor(data1$Gender)
data1$EDU<-as.factor(data1$EDU)

glimpse(data1)
## Rows: 1,925
## Columns: 6
## $ Gender    <fct> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU       <fct> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
summary(data1)
##  Gender   EDU            BF              BM          Happiness    
##  0:1136   1: 233   Min.   :1.000   Min.   :1.000   Min.   :1.400  
##  1: 789   2: 472   1st Qu.:2.600   1st Qu.:2.400   1st Qu.:3.000  
##           3:1022   Median :3.200   Median :3.000   Median :3.600  
##           4: 198   Mean   :3.172   Mean   :2.976   Mean   :3.547  
##                    3rd Qu.:3.800   3rd Qu.:3.600   3rd Qu.:4.000  
##                    Max.   :5.000   Max.   :5.000   Max.   :5.000  
##      Peace      
##  Min.   :1.200  
##  1st Qu.:3.200  
##  Median :3.600  
##  Mean   :3.564  
##  3rd Qu.:4.000  
##  Max.   :5.000
# 49p
data2<-data1 %>% select(-1,-2)
glimpse(data2)
## Rows: 1,925
## Columns: 4
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
cor(data2)  # correlation : 상관계수
##                  BF        BM Happiness     Peace
## BF        1.0000000 0.6399285 0.5296098 0.3625608
## BM        0.6399285 1.0000000 0.5171894 0.3568472
## Happiness 0.5296098 0.5171894 1.0000000 0.5681350
## Peace     0.3625608 0.3568472 0.5681350 1.0000000
data("airquality")
glimpse(airquality)
## Rows: 153
## Columns: 6
## $ Ozone   <int> 41, 36, 12, 18, NA, 28, 23, 19, 8, NA, 7, 16, 11, 14, 18, 14, …
## $ Solar.R <int> 190, 118, 149, 313, NA, NA, 299, 99, 19, 194, NA, 256, 290, 27…
## $ Wind    <dbl> 7.4, 8.0, 12.6, 11.5, 14.3, 14.9, 8.6, 13.8, 20.1, 8.6, 6.9, 9…
## $ Temp    <int> 67, 72, 74, 62, 56, 66, 65, 59, 61, 69, 74, 69, 66, 68, 58, 64…
## $ Month   <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,…
## $ Day     <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,…
colSums(is.na(airquality))
##   Ozone Solar.R    Wind    Temp   Month     Day 
##      37       7       0       0       0       0
airquality <- na.omit(airquality) # 결측값을 삭제하는 함수
colSums(is.na(airquality))
##   Ozone Solar.R    Wind    Temp   Month     Day 
##       0       0       0       0       0       0
airquality <- airquality %>% select(1:4)
glimpse(airquality)
## Rows: 111
## Columns: 4
## $ Ozone   <int> 41, 36, 12, 18, 23, 19, 8, 16, 11, 14, 18, 14, 34, 6, 30, 11, …
## $ Solar.R <int> 190, 118, 149, 313, 299, 99, 19, 256, 290, 274, 65, 334, 307, …
## $ Wind    <dbl> 7.4, 8.0, 12.6, 11.5, 8.6, 13.8, 20.1, 9.7, 9.2, 10.9, 13.2, 1…
## $ Temp    <int> 67, 72, 74, 62, 65, 59, 61, 69, 66, 68, 58, 64, 66, 57, 68, 62…
cor(airquality)
##              Ozone    Solar.R       Wind       Temp
## Ozone    1.0000000  0.3483417 -0.6124966  0.6985414
## Solar.R  0.3483417  1.0000000 -0.1271835  0.2940876
## Wind    -0.6124966 -0.1271835  1.0000000 -0.4971897
## Temp     0.6985414  0.2940876 -0.4971897  1.0000000
plot(airquality$Ozone, airquality$Temp)

plot(airquality$Ozone, airquality$Solar.R)

# 회귀분석

lm(BF~BM, data=data2)
## 
## Call:
## lm(formula = BF ~ BM, data = data2)
## 
## Coefficients:
## (Intercept)           BM  
##      1.3486       0.6126
plot(data2$BF,data2$BM)

# 다중회귀분석 : 독립변수가 2개 이상인 경우 분석
model<-lm(Happiness~Peace+BF+BM,data=data1)
model
## 
## Call:
## lm(formula = Happiness ~ Peace + BF + BM, data = data1)
## 
## Coefficients:
## (Intercept)        Peace           BF           BM  
##      0.5139       0.4575       0.2464       0.2088
library(car)
## Warning: 패키지 'car'는 R 버전 4.2.3에서 작성되었습니다
## 필요한 패키지를 로딩중입니다: carData
## Warning: 패키지 'carData'는 R 버전 4.2.3에서 작성되었습니다
## 
## 다음의 패키지를 부착합니다: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
summary(model)
## 
## Call:
## lm(formula = Happiness ~ Peace + BF + BM, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.89078 -0.32950 -0.00156  0.33644  2.18933 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.51388    0.07556   6.801 1.38e-11 ***
## Peace        0.45747    0.02060  22.209  < 2e-16 ***
## BF           0.24636    0.02211  11.141  < 2e-16 ***
## BM           0.20878    0.02112   9.886  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5448 on 1921 degrees of freedom
## Multiple R-squared:  0.4703, Adjusted R-squared:  0.4695 
## F-statistic: 568.6 on 3 and 1921 DF,  p-value: < 2.2e-16
vif(model) #vif값이 10미만이면 다중공선성이 없음을 추정
##    Peace       BF       BM 
## 1.187424 1.754840 1.746574
# multiple R-squared : 결정계수로 0~1의 범위로 나타남, 모형의 설명력 의미
# 독립변수로 종속변수를 설명할 수 있는지 의미
# 다중회귀분석 시 adjusted R-squared를 이용하여야 함

cor(data2$Happiness, data2$Peace)
## [1] 0.568135
sqrt(0.3228)
## [1] 0.5681549
summary(model)
## 
## Call:
## lm(formula = Happiness ~ Peace + BF + BM, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.89078 -0.32950 -0.00156  0.33644  2.18933 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.51388    0.07556   6.801 1.38e-11 ***
## Peace        0.45747    0.02060  22.209  < 2e-16 ***
## BF           0.24636    0.02211  11.141  < 2e-16 ***
## BM           0.20878    0.02112   9.886  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5448 on 1921 degrees of freedom
## Multiple R-squared:  0.4703, Adjusted R-squared:  0.4695 
## F-statistic: 568.6 on 3 and 1921 DF,  p-value: < 2.2e-16
# y=0.51388+0.45747*Peace+0.24636*BF+0.20878*BM
# BF, BM이 일정할때 Peace 1단위 증가할때 행복은 0.45747만큼 증가한다고 해석
# Peace, BM이 일정할때 BF 1단위 증가할때 행복은 0.24636만큼 증가한다


# p67 정규성 검정

shapiro.test(data1$Happiness)
## 
##  Shapiro-Wilk normality test
## 
## data:  data1$Happiness
## W = 0.96442, p-value < 2.2e-16
# 귀무가설 : Happiness는 정규성을 만족한다.
# 대립가설 : Happiness정규성을 만족하지 않는다. 
hist(data1$Happiness)
mean(data1$Happiness)
## [1] 3.547065
median(data1$Happiness)
## [1] 3.6
library(psych)
## Warning: 패키지 'psych'는 R 버전 4.2.3에서 작성되었습니다
## 
## 다음의 패키지를 부착합니다: 'psych'
## The following object is masked from 'package:car':
## 
##     logit

describe(data1$Happiness)
##    vars    n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 1925 3.55 0.75    3.6    3.57 0.59 1.4   5   3.6 -0.37     -0.2 0.02
# 71p 비모수 검정

wilcox.test(data1$Happiness,mu=3.5)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  data1$Happiness
## V = 1029154, p-value = 2.782e-06
## alternative hypothesis: true location is not equal to 3.5
par(mfrow=c(1,2))
hist(data1$Happiness-data1$Peace)
boxplot(data1$Happiness-data1$Peace)

shapiro.test(data1$Happiness-data1$Peace)
## 
##  Shapiro-Wilk normality test
## 
## data:  data1$Happiness - data1$Peace
## W = 0.98359, p-value = 4.598e-14
# 독립표본 t.test : 두집단의 평균차이 검정

wilcox.test(data1$Happiness~data1$Gender)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data1$Happiness by data1$Gender
## W = 463050, p-value = 0.211
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(data1$BF~data1$Gender)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data1$BF by data1$Gender
## W = 403502, p-value = 0.0001866
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(data1$BM~data1$Gender)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data1$BM by data1$Gender
## W = 425755, p-value = 0.06109
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(data1$Peace~data1$Gender)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data1$Peace by data1$Gender
## W = 473455, p-value = 0.03373
## alternative hypothesis: true location shift is not equal to 0
par(mfrow=c(1,2))
boxplot(data1$Happiness~data1$Gender)
boxplot(data1$BF~data1$Gender)

# 86p 
cor(data2)
##                  BF        BM Happiness     Peace
## BF        1.0000000 0.6399285 0.5296098 0.3625608
## BM        0.6399285 1.0000000 0.5171894 0.3568472
## Happiness 0.5296098 0.5171894 1.0000000 0.5681350
## Peace     0.3625608 0.3568472 0.5681350 1.0000000
cor.test(data1$BF, data1$Happiness)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$BF and data1$Happiness
## t = 27.38, df = 1923, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4966852 0.5610123
## sample estimates:
##       cor 
## 0.5296098
cor.test(data1$BM, data1$Happiness)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$BM and data1$Happiness
## t = 26.499, df = 1923, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4836889 0.5491767
## sample estimates:
##       cor 
## 0.5171894
cor.test(data1$Peace, data1$Happiness)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$Peace and data1$Happiness
## t = 30.274, df = 1923, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5370908 0.5976421
## sample estimates:
##      cor 
## 0.568135
# 귀무가설 : 두 변수는 상관성이 없다. 독립이다.
# 대립가설 : 두 변수는 상관성이 있다. 연관되어 있다. 



# 90p
data1 %>% count(Gender)
##   Gender    n
## 1      0 1136
## 2      1  789
data2_g0<-data1 %>% filter(Gender==0)
cor(data2_g0$Happiness, data2_g0$BM)
## [1] 0.4770279
data2_g1<-data1 %>% filter(Gender==1)
cor(data2_g1$Happiness, data2_g1$BM)
## [1] 0.5771675
data1 %>% count(EDU)
##   EDU    n
## 1   1  233
## 2   2  472
## 3   3 1022
## 4   4  198
data2_g0_EDU1<-data1 %>% filter(EDU==1)
data2_g0_EDU2<-data1 %>% filter(EDU==2)
data2_g0_EDU3<-data1 %>% filter(EDU==3)
data2_g0_EDU4<-data1 %>% filter(EDU==4)

cor(data2_g0_EDU1$Happiness, data2_g0_EDU1$BM)
## [1] 0.4608886
cor(data2_g0_EDU2$Happiness, data2_g0_EDU2$BM)
## [1] 0.5138855
cor(data2_g0_EDU3$Happiness, data2_g0_EDU3$BM)
## [1] 0.5423291
cor(data2_g0_EDU4$Happiness, data2_g0_EDU4$BM)
## [1] 0.4837608
# 92p

bs.out2<-lm(Happiness~BM, data=data1)
summary(bs.out2)
## 
## Call:
## lm(formula = Happiness ~ BM, data = data1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.1591 -0.4577  0.0418  0.4409  1.9386 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.06599    0.05777   35.77   <2e-16 ***
## BM           0.49771    0.01878   26.50   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6404 on 1923 degrees of freedom
## Multiple R-squared:  0.2675, Adjusted R-squared:  0.2671 
## F-statistic: 702.2 on 1 and 1923 DF,  p-value: < 2.2e-16
library(car)
sreg.res1<-residuals(bs.out2)
durbinWatsonTest(sreg.res1)
## [1] 1.787942
bs.out3<-lm(Happiness~BM+BF, data=data1)
summary(bs.out3)
## 
## Call:
## lm(formula = Happiness ~ BM + BF, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.23134 -0.40553  0.02014  0.41352  1.86210 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.60995    0.06412   25.11   <2e-16 ***
## BM           0.29054    0.02331   12.47   <2e-16 ***
## BF           0.33817    0.02435   13.89   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6106 on 1922 degrees of freedom
## Multiple R-squared:  0.3343, Adjusted R-squared:  0.3336 
## F-statistic: 482.6 on 2 and 1922 DF,  p-value: < 2.2e-16
sreg.res2<-residuals(bs.out3)
durbinWatsonTest(sreg.res2)
## [1] 1.820914
# forward : 가장 유의한 변수부터 추가, 변수선택방법 = 전진선택법
# backward : 가장 유의하지 않은 변수부터 제거, 후진제거법
step(lm(Peace~BF+BM+Happiness+Gender+EDU, data1),direction="forward")
## Start:  AIC=-2402.04
## Peace ~ BF + BM + Happiness + Gender + EDU
## 
## Call:
## lm(formula = Peace ~ BF + BM + Happiness + Gender + EDU, data = data1)
## 
## Coefficients:
## (Intercept)           BF           BM    Happiness      Gender1         EDU2  
##   1.8235660    0.0541215    0.0463931    0.4407108   -0.0615161   -0.1346394  
##        EDU3         EDU4  
##  -0.1394468    0.0001638
step(lm(Peace~BF+BM+Happiness+Gender+EDU, data1),direction="backward")
## Start:  AIC=-2402.04
## Peace ~ BF + BM + Happiness + Gender + EDU
## 
##             Df Sum of Sq    RSS     AIC
## <none>                   548.15 -2402.0
## - BM         1     1.345 549.50 -2399.3
## - BF         1     1.662 549.82 -2398.2
## - Gender     1     1.692 549.85 -2398.1
## - EDU        3     6.329 554.48 -2385.9
## - Happiness  1   136.939 685.09 -1974.8
## 
## Call:
## lm(formula = Peace ~ BF + BM + Happiness + Gender + EDU, data = data1)
## 
## Coefficients:
## (Intercept)           BF           BM    Happiness      Gender1         EDU2  
##   1.8235660    0.0541215    0.0463931    0.4407108   -0.0615161   -0.1346394  
##        EDU3         EDU4  
##  -0.1394468    0.0001638
summary(lm(Peace~BF+BM+Happiness+Gender+EDU, data=data1))
## 
## Call:
## lm(formula = Peace ~ BF + BM + Happiness + Gender + EDU, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.77094 -0.34508  0.03346  0.33155  1.76489 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.8235660  0.0740713  24.619  < 2e-16 ***
## BF           0.0541215  0.0224469   2.411 0.015998 *  
## BM           0.0463931  0.0213890   2.169 0.030204 *  
## Happiness    0.4407108  0.0201386  21.884  < 2e-16 ***
## Gender1     -0.0615161  0.0252854  -2.433 0.015071 *  
## EDU2        -0.1346394  0.0432228  -3.115 0.001867 ** 
## EDU3        -0.1394468  0.0394577  -3.534 0.000419 ***
## EDU4         0.0001638  0.0525968   0.003 0.997516    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5347 on 1917 degrees of freedom
## Multiple R-squared:  0.3401, Adjusted R-squared:  0.3377 
## F-statistic: 141.2 on 7 and 1917 DF,  p-value: < 2.2e-16
library(mixlm)
## Warning: 패키지 'mixlm'는 R 버전 4.2.3에서 작성되었습니다
## 
## 다음의 패키지를 부착합니다: 'mixlm'
## The following object is masked from 'package:psych':
## 
##     fparse
## The following object is masked from 'package:dplyr':
## 
##     tally
## The following objects are masked from 'package:stats':
## 
##     glm, lm
bs.out4<-lm(Peace~BF+BM+Happiness+Gender+EDU, data=data1)
summary(bs.out4)
## 
## Call:
## lm(formula = Peace ~ BF + BM + Happiness + Gender + EDU, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.77094 -0.34508  0.03346  0.33155  1.76489 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.72433    0.06592  26.158  < 2e-16 ***
## BF           0.05412    0.02245   2.411 0.015998 *  
## BM           0.04639    0.02139   2.169 0.030204 *  
## Happiness    0.44071    0.02014  21.884  < 2e-16 ***
## Gender(1)    0.03076    0.01264   2.433 0.015071 *  
## EDU(2)       0.06848    0.02945   2.325 0.020150 *  
## EDU(3)      -0.06616    0.02297  -2.880 0.004023 ** 
## EDU(4)      -0.07097    0.01910  -3.716 0.000208 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## s: 0.5347 on 1917 degrees of freedom
## Multiple R-squared: 0.3401,
## Adjusted R-squared: 0.3377 
## F-statistic: 141.2 on 7 and 1917 DF,  p-value: < 2.2e-16
bs.out5=stepWiseBack(bs.out4, alpha.enter=0.05, alpha.remove=0.05,full=TRUE)
## Stepwise regression (backward-forward), alpha-to-remove: 0.05, alpha-to-enter: 0.05
## 
## Full model: Peace ~ BF + BM + Happiness + Gender + EDU
## 
## --= Step (backward) 1 =-- 
## Single term deletions
## 
## Model:
## Peace ~ BF + BM + Happiness + Gender + EDU
##           Df Sum of Sq    RSS     AIC  F value    Pr(>F)    
## <none>                 548.15 -2402.0                       
## BF         1     1.662 549.82 -2398.2   5.8134   0.01600 *  
## BM         1     1.345 549.50 -2399.3   4.7047   0.03020 *  
## Happiness  1   136.939 685.09 -1974.8 478.9039 < 2.2e-16 ***
## Gender     1     1.692 549.85 -2398.1   5.9188   0.01507 *  
## EDU        3     6.329 554.48 -2385.9   7.3775 6.487e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
bs.out6=lm(Peace~BF+BM+Happiness+factor(Gender)+factor(EDU), data=Data1)
summary(bs.out6)
## 
## Call:
## lm(formula = Peace ~ BF + BM + Happiness + factor(Gender) + factor(EDU), 
##     data = Data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.77094 -0.34508  0.03346  0.33155  1.76489 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        1.72433    0.06592  26.158  < 2e-16 ***
## BF                 0.05412    0.02245   2.411 0.015998 *  
## BM                 0.04639    0.02139   2.169 0.030204 *  
## Happiness          0.44071    0.02014  21.884  < 2e-16 ***
## factor(Gender)(1)  0.03076    0.01264   2.433 0.015071 *  
## factor(EDU)(2)     0.06848    0.02945   2.325 0.020150 *  
## factor(EDU)(3)    -0.06616    0.02297  -2.880 0.004023 ** 
## factor(EDU)(4)    -0.07097    0.01910  -3.716 0.000208 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## s: 0.5347 on 1917 degrees of freedom
## Multiple R-squared: 0.3401,
## Adjusted R-squared: 0.3377 
## F-statistic: 141.2 on 7 and 1917 DF,  p-value: < 2.2e-16