BMA

library(foreign)
## Warning: package 'foreign' was built under R version 3.2.5
r=read.dta("C:/Users/BINH THANG/Dropbox/Korea/STudy/Thesis/data management/DataR/dataR3.dta")

r1 <- subset(r, cost_inc<180001)

r1$logC=log10(r1$cost_inc)

attach(r1)

newdata2=r1

newdata2$c1=as.factor(newdata2$c1)
newdata2$h1=as.factor(newdata2$h1)
newdata2$label1=as.factor(newdata2$label1)
newdata2$policy=as.factor(newdata2$policy)
newdata2$educ2=as.factor(newdata2$educ2)
newdata2$ter_in=as.factor(newdata2$ter_in)
newdata2$age_group=as.factor(newdata2$age_group)
newdata2$d1a=as.factor(newdata2$d1a)
newdata2$selfhealth=as.factor(newdata2$selfhealth)
newdata2$b18a=as.factor(newdata2$b18a)
newdata2$b16a=as.factor(newdata2$b16a)
newdata2$b6a=as.factor(newdata2$b6a)
newdata2$smostt=as.factor(newdata2$smostt)
newdata2$reasons1=as.factor(newdata2$reasons1)
newdata2$ter_in=as.factor(newdata2$ter_in)
newdata2$group_age1=as.factor(newdata2$group_age1)
newdata2$policy_a=as.factor(newdata2$policy_a)
attach(newdata2 )
## The following objects are masked from r1:
## 
##     a1, advice, advice1, ag, age_group, anticam, anticam2, b1,
##     b10, b10a1, b10a2, b10a3, b10a4, b10a5, b10a6, b10a7, b11,
##     b11a, b11a2, b11a3, b12, b12a, b13, b14, b15, b16, b16a, b17,
##     b18, b18a, b1a, b2, b2a1, b3, b4, b5, b5a, b6, b6a, b6a1,
##     b6a2, b6a3, b6a4, b6a5, b6a6, b6a7, b6a7a, b7, b8, b9, br,
##     branch, branch1, branch2, branch3, c1, c2, c23a, c3, c4, c5,
##     c6, c7, c8, c9, COST, cost_inc, cost1, costincrease, ct, d1,
##     d10, d11, d1a, d2, d3, d3a, d4, d5, d6, d7, d8, d9, Decision,
##     e1, e2, edu, educ1, educ2, f1, ghi1, ghi2, ghiro2,
##     giadinhkoUH, group_age, group_age1, h1, h10a, h10a1, h10a10,
##     h10a11, h10a11a, h10a2, h10a3, h10a4, h10a5, h10a6, h10a7,
##     h10a8, h10a9, h12, h12a, h12a_1, h12log, h13, h2, h3, h4, h5,
##     h6, h7, h8, h9, ha000, itc1, itc2, l1, l2, l3, l4, l5, l6,
##     label1, label2, logC, moneyspent, msdt, n01, n02, n03, n05,
##     n06, n07, n08, n1, n10, n100, n101, n102, n103, n11, n12, n13,
##     n14, n15, n16, n1b, n2, n3, n35, n36, n37, n38, n39,
##     n3posterb, n4, n40, n41, n42, n43, n44, n45, n46, n47, n48,
##     n49, n5, n50, n51, n52, n53, n54, n55, n56, n57, n58, n59, n6,
##     n60, n61, n61a, n62, n62a, n63, n63a, n64, n64a, n65, n65a,
##     n66, n66a, n67, n67a, n68, n68a, n7, n77, n78, n7tren, n8,
##     n88, n89, n8nha, n9, n97, n98, n99, n9khach, noEnvi2, occup1,
##     policy, policy_a, policy2, reasons, reasons1, s1, Screening,
##     selfhealth, SH1, smostt, ter_fa1, ter_in, tertile_fa,
##     tertile_indi, test, unitsdiffi1, var242, w1, w2, w3, w4
t2<-subset(newdata2, select =c(logC,age_group,d1a, educ2, ter_in, selfhealth,h1, b16a, b18a, c1, smostt,policy_a))

t2=na.omit(t2)

yvar = t2[,1]
xvars = t2[,-1]
reg = lm(logC ~ ., data=t2)

step(reg, direction="both")
## Start:  AIC=-1297.44
## logC ~ age_group + d1a + educ2 + ter_in + selfhealth + h1 + b16a + 
##     b18a + c1 + smostt + policy_a
## 
##              Df Sum of Sq    RSS     AIC
## - age_group   4   0.13027 17.430 -1302.3
## - policy_a    2   0.00181 17.301 -1301.4
## - ter_in      2   0.03401 17.333 -1300.6
## - d1a         1   0.00231 17.302 -1299.4
## - c1          1   0.00297 17.302 -1299.4
## - h1          1   0.02488 17.324 -1298.8
## - b16a        1   0.04309 17.342 -1298.4
## - b18a        1   0.05931 17.358 -1298.0
## - smostt      2   0.14747 17.447 -1297.9
## <none>                    17.299 -1297.4
## - selfhealth  1   0.38316 17.682 -1290.3
## - educ2       2   0.52021 17.819 -1289.0
## 
## Step:  AIC=-1302.3
## logC ~ d1a + educ2 + ter_in + selfhealth + h1 + b16a + b18a + 
##     c1 + smostt + policy_a
## 
##              Df Sum of Sq    RSS     AIC
## - policy_a    2   0.00473 17.434 -1306.2
## - ter_in      2   0.05082 17.480 -1305.1
## - c1          1   0.00399 17.433 -1304.2
## - h1          1   0.01942 17.449 -1303.8
## - b16a        1   0.03991 17.469 -1303.3
## - d1a         1   0.04671 17.476 -1303.2
## - smostt      2   0.13815 17.568 -1303.0
## - b18a        1   0.06219 17.492 -1302.8
## <none>                    17.430 -1302.3
## + age_group   4   0.13027 17.299 -1297.4
## - selfhealth  1   0.42705 17.857 -1294.2
## - educ2       2   0.71720 18.147 -1289.4
## 
## Step:  AIC=-1306.18
## logC ~ d1a + educ2 + ter_in + selfhealth + h1 + b16a + b18a + 
##     c1 + smostt
## 
##              Df Sum of Sq    RSS     AIC
## - ter_in      2   0.05295 17.487 -1308.9
## - c1          1   0.00348 17.438 -1308.1
## - h1          1   0.01760 17.452 -1307.8
## - b16a        1   0.04148 17.476 -1307.2
## - d1a         1   0.04960 17.484 -1307.0
## - smostt      2   0.13976 17.574 -1306.8
## - b18a        1   0.06322 17.497 -1306.7
## <none>                    17.434 -1306.2
## + policy_a    2   0.00473 17.430 -1302.3
## + age_group   4   0.13319 17.301 -1301.4
## - selfhealth  1   0.42238 17.857 -1298.2
## - educ2       2   0.73103 18.165 -1293.0
## 
## Step:  AIC=-1308.91
## logC ~ d1a + educ2 + selfhealth + h1 + b16a + b18a + c1 + smostt
## 
##              Df Sum of Sq    RSS     AIC
## - c1          1   0.00672 17.494 -1310.8
## - h1          1   0.01947 17.507 -1310.5
## - b16a        1   0.04670 17.534 -1309.8
## - d1a         1   0.05101 17.538 -1309.7
## - smostt      2   0.14065 17.628 -1309.6
## - b18a        1   0.06109 17.548 -1309.5
## <none>                    17.487 -1308.9
## + ter_in      2   0.05295 17.434 -1306.2
## + policy_a    2   0.00686 17.480 -1305.1
## + age_group   4   0.15159 17.336 -1304.6
## - selfhealth  1   0.43983 17.927 -1300.5
## - educ2       2   0.76965 18.257 -1294.9
## 
## Step:  AIC=-1310.75
## logC ~ d1a + educ2 + selfhealth + h1 + b16a + b18a + smostt
## 
##              Df Sum of Sq    RSS     AIC
## - h1          1   0.01921 17.513 -1312.3
## - b16a        1   0.04751 17.541 -1311.6
## - d1a         1   0.04778 17.542 -1311.6
## - b18a        1   0.06066 17.555 -1311.3
## <none>                    17.494 -1310.8
## + c1          1   0.00672 17.487 -1308.9
## - smostt      2   0.27239 17.766 -1308.3
## + ter_in      2   0.05620 17.438 -1308.1
## + policy_a    2   0.00626 17.488 -1306.9
## + age_group   4   0.15317 17.341 -1306.4
## - selfhealth  1   0.43578 17.930 -1302.4
## - educ2       2   0.76747 18.261 -1296.8
## 
## Step:  AIC=-1312.29
## logC ~ d1a + educ2 + selfhealth + b16a + b18a + smostt
## 
##              Df Sum of Sq    RSS     AIC
## - b16a        1   0.03915 17.552 -1313.4
## - d1a         1   0.05016 17.563 -1313.1
## - b18a        1   0.06565 17.579 -1312.7
## <none>                    17.513 -1312.3
## + h1          1   0.01921 17.494 -1310.8
## + c1          1   0.00646 17.507 -1310.5
## - smostt      2   0.26700 17.780 -1310.0
## + ter_in      2   0.05802 17.455 -1309.7
## + policy_a    2   0.00348 17.510 -1308.4
## + age_group   4   0.14605 17.367 -1307.8
## - selfhealth  1   0.42919 17.942 -1304.2
## - educ2       2   0.79381 18.307 -1297.7
## 
## Step:  AIC=-1313.36
## logC ~ d1a + educ2 + selfhealth + b18a + smostt
## 
##              Df Sum of Sq    RSS     AIC
## - d1a         1   0.05296 17.605 -1314.1
## - b18a        1   0.05495 17.607 -1314.0
## <none>                    17.552 -1313.4
## + b16a        1   0.03915 17.513 -1312.3
## + h1          1   0.01085 17.541 -1311.6
## + c1          1   0.00725 17.545 -1311.5
## - smostt      2   0.26407 17.816 -1311.1
## + ter_in      2   0.06299 17.489 -1310.9
## + policy_a    2   0.00537 17.547 -1309.5
## + age_group   4   0.14213 17.410 -1308.8
## - selfhealth  1   0.44890 18.001 -1304.8
## - educ2       2   0.77165 18.324 -1299.3
## 
## Step:  AIC=-1314.09
## logC ~ educ2 + selfhealth + b18a + smostt
## 
##              Df Sum of Sq    RSS     AIC
## - b18a        1   0.04480 17.650 -1315.0
## <none>                    17.605 -1314.1
## + d1a         1   0.05296 17.552 -1313.4
## + b16a        1   0.04195 17.563 -1313.1
## + h1          1   0.01244 17.593 -1312.4
## - smostt      2   0.24764 17.853 -1312.2
## + c1          1   0.00374 17.602 -1312.2
## + ter_in      2   0.06711 17.538 -1311.7
## + age_group   4   0.19152 17.414 -1310.7
## + policy_a    2   0.00830 17.597 -1310.3
## - selfhealth  1   0.45664 18.062 -1305.4
## - educ2       2   0.96243 18.568 -1295.8
## 
## Step:  AIC=-1315.03
## logC ~ educ2 + selfhealth + smostt
## 
##              Df Sum of Sq    RSS     AIC
## <none>                    17.650 -1315.0
## + b18a        1   0.04480 17.605 -1314.1
## + d1a         1   0.04281 17.607 -1314.0
## + b16a        1   0.03148 17.619 -1313.8
## + h1          1   0.01659 17.633 -1313.4
## + c1          1   0.00364 17.646 -1313.1
## - smostt      2   0.25653 17.907 -1313.0
## + ter_in      2   0.06317 17.587 -1312.5
## + age_group   4   0.18533 17.465 -1311.5
## + policy_a    2   0.00942 17.641 -1311.2
## - selfhealth  1   0.45559 18.106 -1306.3
## - educ2       2   0.97460 18.625 -1296.5
## 
## Call:
## lm(formula = logC ~ educ2 + selfhealth + smostt, data = t2)
## 
## Coefficients:
##    (Intercept)          educ22          educ23  selfhealthgood  
##        4.66055         0.04186         0.13784         0.06804  
##   smosttmedium     smosttheavy  
##        0.04924         0.06749

Mo hinh va bieu do

library(BMA)
## Warning: package 'BMA' was built under R version 3.2.5
## Loading required package: survival
## Warning: package 'survival' was built under R version 3.2.5
## Loading required package: leaps
## Warning: package 'leaps' was built under R version 3.2.5
## Loading required package: robustbase
## Warning: package 'robustbase' was built under R version 3.2.5
## 
## Attaching package: 'robustbase'
## The following object is masked from 'package:survival':
## 
##     heart
## Loading required package: inline
## Warning: package 'inline' was built under R version 3.2.5
## Loading required package: rrcov
## Warning: package 'rrcov' was built under R version 3.2.5
## Scalable Robust Estimators with High Breakdown Point (version 1.4-3)
bma = bicreg(xvars, yvar, strict=FALSE, OR=20)
summary(bma)
## 
## Call:
## bicreg(x = xvars, y = yvar, strict = FALSE, OR = 20)
## 
## 
##   18  models were selected
##  Best  5  models (cumulative posterior probability =  0.6577 ): 
## 
##                  p!=0    EV         SD        model 1    model 2  
## Intercept        100.0   4.7382241  0.019749    4.73789    4.74997
## age_groupgr3039    3.2   0.0009045  0.007020      .          .    
## age_groupgr4049    2.3  -0.0003877  0.004621      .          .    
## age_groupgr5059   11.8  -0.0062094  0.019644      .       -0.05237
## age_group60plus    0.0   0.0000000  0.000000      .          .    
## d1amarried         2.9  -0.0005841  0.005026      .          .    
## educ22             5.5   0.0021859  0.011006      .          .    
## educ23           100.0   0.0890641  0.024483    0.08723    0.07691
## ter_in2            5.2   0.0016958  0.008939      .          .    
## ter_in3            1.9  -0.0001157  0.003218      .          .    
## selfhealthgood    97.1   0.0669088  0.023414    0.06915    0.06750
## h12                2.4  -0.0003771  0.004056      .          .    
## b16a1              2.2  -0.0003839  0.004998      .          .    
## b18abad            3.0   0.0006232  0.005127      .          .    
## c12                9.3  -0.0047015  0.017411      .          .    
## smosttmedium       2.2   0.0002573  0.003529      .          .    
## smosttheavy        5.5   0.0017750  0.009018      .          .    
## policy_a1          1.9  -0.0001179  0.003229      .          .    
## policy_a2          2.2  -0.0003480  0.004744      .          .    
##                                                                   
## nVar                                              2          3    
## r2                                              0.068      0.075  
## BIC                                           -17.48522  -14.77429
## post prob                                       0.378      0.097  
##                  model 3    model 4    model 5  
## Intercept          4.74056    4.71247    4.72378
## age_groupgr3039      .          .          .    
## age_groupgr4049      .          .          .    
## age_groupgr5059      .          .          .    
## age_group60plus      .          .          .    
## d1amarried           .          .          .    
## educ22               .        0.03949      .    
## educ23             0.09695    0.11551    0.09530
## ter_in2              .          .          .    
## ter_in3              .          .          .    
## selfhealthgood     0.07226    0.06399    0.07070
## h12                  .          .          .    
## b16a1                .          .          .    
## b18abad              .          .          .    
## c12               -0.05038      .          .    
## smosttmedium         .          .          .    
## smosttheavy          .          .        0.03250
## policy_a1            .          .          .    
## policy_a2            .          .          .    
##                                                 
## nVar                 3          3          3    
## r2                 0.074      0.073      0.073  
## BIC              -14.17195  -13.64279  -13.61567
## post prob          0.072      0.055      0.055

image.plot(bma)

install.packages(“relaimpo”)

which vars is importants

model1 = lm(logC~., data=t2)

library(relaimpo)
## Warning: package 'relaimpo' was built under R version 3.2.5
## Loading required package: MASS
## Loading required package: boot
## 
## Attaching package: 'boot'
## The following object is masked from 'package:robustbase':
## 
##     salinity
## The following object is masked from 'package:survival':
## 
##     aml
## Loading required package: survey
## Warning: package 'survey' was built under R version 3.2.5
## Loading required package: grid
## Loading required package: Matrix
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
## Loading required package: mitools
## Warning: package 'mitools' was built under R version 3.2.5
## This is the global version of package relaimpo.
## If you are a non-US user, a version with the interesting additional metric pmvd is available
## from Ulrike Groempings web site at prof.beuth-hochschule.de/groemping.
metrics=calc.relimp(model1, type=c("lmg"))

metrics
## Response variable: logC 
## Total response variance: 0.04621148 
## Analysis based on 419 observations 
## 
## 18 Regressors: 
## Some regressors combined in groups: 
##         Group  age_group : age_groupgr3039 age_groupgr4049 age_groupgr5059 age_group60plus 
##         Group  educ2 : educ22 educ23 
##         Group  ter_in : ter_in2 ter_in3 
##         Group  smostt : smosttmedium smosttheavy 
##         Group  policy_a : policy_a1 policy_a2 
## 
##  Relative importance of 11 (groups of) regressors assessed: 
##  age_group educ2 ter_in smostt policy_a d1a selfhealth h1 b16a b18a c1 
##  
## Proportion of variance explained by model: 10.44%
## Metrics are not normalized (rela=FALSE). 
## 
## Relative importance metrics: 
## 
##                     lmg
## age_group  0.0200875810
## educ2      0.0373578363
## ter_in     0.0031377768
## smostt     0.0052965668
## policy_a   0.0003172111
## d1a        0.0048398829
## selfhealth 0.0254845987
## h1         0.0016147509
## b16a       0.0018942797
## b18a       0.0032299955
## c1         0.0011670414
## 
## Average coefficients for different model sizes: 
## 
##                       1group       2groups       3groups      4groups
## age_groupgr3039  0.000446899  0.0008963928  0.0013424084  0.001808269
## age_groupgr4049 -0.064030447 -0.0603790335 -0.0566866696 -0.052960998
## age_groupgr5059 -0.105138831 -0.1001093303 -0.0950382670 -0.089944017
## age_group60plus -0.085031354 -0.0783814902 -0.0717668141 -0.065209248
## d1a             -0.049692105 -0.0431291919 -0.0372362694 -0.031934413
## educ22           0.053227138  0.0503693935  0.0475680649  0.044839655
## educ23           0.134294102  0.1316710282  0.1290289035  0.126395842
## ter_in2          0.035622950  0.0342790552  0.0325963851  0.030745648
## ter_in3          0.016707055  0.0156455026  0.0141336859  0.012333854
## selfhealth       0.079762494  0.0769257553  0.0745093447  0.072451722
## h1              -0.021083514 -0.0196572100 -0.0185791047 -0.017787456
## b16a            -0.019892078 -0.0218696173 -0.0236920850 -0.025331012
## b18a             0.023588910  0.0247031036  0.0255310866  0.026130881
## c1              -0.003261323 -0.0107447997 -0.0160511808 -0.019482341
## smosttmedium     0.007781878  0.0143748671  0.0198925641  0.024521555
## smosttheavy      0.008369407  0.0188615609  0.0276980684  0.035129151
## policy_a1        0.001323079  0.0002564719 -0.0002893969 -0.000502695
## policy_a2       -0.011580535 -0.0095336537 -0.0078323045 -0.006491841
##                       5groups       6groups      7groups       8groups
## age_groupgr3039  0.0023082728  0.0028499769  0.003435992  0.0040652349
## age_groupgr4049 -0.0492204580 -0.0454919243 -0.041808878 -0.0382101617
## age_groupgr5059 -0.0848499046 -0.0797830184 -0.074773556 -0.0698546803
## age_group60plus -0.0587331396 -0.0523649773 -0.046133574 -0.0400706575
## d1a             -0.0271558212 -0.0228440585 -0.018953664 -0.0154489379
## educ22           0.0421981705  0.0396547208  0.037217175  0.0348898978
## educ23           0.1237989249  0.1212629615  0.118809501  0.1164560391
## ter_in2          0.0288544934  0.0270152733  0.025292217  0.0237279393
## ter_in3          0.0103677039  0.0083247489  0.006269863  0.0042497443
## selfhealth       0.0706970549  0.0691951011  0.067900557  0.0667719462
## h1              -0.0172302922 -0.0168642435 -0.016653073 -0.0165660642
## b16a            -0.0267628582 -0.0279691080 -0.028936452 -0.0296567771
## b18a             0.0265424083  0.0267913073  0.026892832  0.0268552808
## c1              -0.0213134307 -0.0217920759 -0.021137716 -0.0195409002
## smosttmedium     0.0284254962  0.0317447902  0.034597387  0.0370803803
## smosttheavy      0.0413823166  0.0466607936  0.051143311  0.0549848741
## policy_a1       -0.0005310473 -0.0004875677 -0.000456894 -0.0005007053
## policy_a2       -0.0055153556 -0.0048952793 -0.004614693 -0.0046481014
##                       9groups      10groups     11groups
## age_groupgr3039  0.0047336777  0.0054347439  0.006159504
## age_groupgr4049 -0.0347392171 -0.0314435986 -0.028374533
## age_groupgr5059 -0.0650627606 -0.0604378063 -0.056023850
## age_group60plus -0.0342117233 -0.0285969329 -0.023271812
## d1a             -0.0123018161 -0.0094889176 -0.006987929
## educ22           0.0326735764  0.0305651526  0.028557817
## educ23           0.1142153932  0.1120951688  0.110097250
## ter_in2          0.0223491894  0.0211716777  0.020203773
## ter_in3          0.0022980655  0.0004391681 -0.001309746
## selfhealth       0.0657700926  0.0648562173  0.063989677
## h1              -0.0165764354 -0.0166599949 -0.016794248
## b16a            -0.0301268306 -0.0303475763 -0.030323422
## b18a             0.0266826486  0.0263763904  0.025936263
## c1              -0.0171625509 -0.0141333718 -0.010553656
## smosttmedium     0.0392722063  0.0412353582  0.043019675
## smosttheavy      0.0583183172  0.0612565081  0.063895226
## policy_a1       -0.0006625225 -0.0009717927 -0.001447362
## policy_a2       -0.0049617275 -0.0055135566 -0.006253434
#bootstrap

boot = boot.relimp(model1, b=1000,
type=c("lmg"), fixed=F)

booteval.relimp(boot, typesel=c("lmg"),
level=0.9, bty="perc", nodiff=T)
## Response variable: logC 
## Total response variance: 0.04621148 
## Analysis based on 419 observations 
## 
## 18 Regressors: 
## Some regressors combined in groups: 
##         Group  age_group : age_groupgr3039 age_groupgr4049 age_groupgr5059 age_group60plus 
##         Group  educ2 : educ22 educ23 
##         Group  ter_in : ter_in2 ter_in3 
##         Group  smostt : smosttmedium smosttheavy 
##         Group  policy_a : policy_a1 policy_a2 
## 
##  Relative importance of 11 (groups of) regressors assessed: 
##  age_group educ2 ter_in smostt policy_a d1a selfhealth h1 b16a b18a c1 
##  
## Proportion of variance explained by model: 10.44%
## Metrics are not normalized (rela=FALSE). 
## 
## Relative importance metrics: 
## 
##                     lmg
## age_group  0.0200875810
## educ2      0.0373578363
## ter_in     0.0031377768
## smostt     0.0052965668
## policy_a   0.0003172111
## d1a        0.0048398829
## selfhealth 0.0254845987
## h1         0.0016147509
## b16a       0.0018942797
## b18a       0.0032299955
## c1         0.0011670414
## 
## Average coefficients for different model sizes: 
## 
##                       1group       2groups       3groups      4groups
## age_groupgr3039  0.000446899  0.0008963928  0.0013424084  0.001808269
## age_groupgr4049 -0.064030447 -0.0603790335 -0.0566866696 -0.052960998
## age_groupgr5059 -0.105138831 -0.1001093303 -0.0950382670 -0.089944017
## age_group60plus -0.085031354 -0.0783814902 -0.0717668141 -0.065209248
## d1a             -0.049692105 -0.0431291919 -0.0372362694 -0.031934413
## educ22           0.053227138  0.0503693935  0.0475680649  0.044839655
## educ23           0.134294102  0.1316710282  0.1290289035  0.126395842
## ter_in2          0.035622950  0.0342790552  0.0325963851  0.030745648
## ter_in3          0.016707055  0.0156455026  0.0141336859  0.012333854
## selfhealth       0.079762494  0.0769257553  0.0745093447  0.072451722
## h1              -0.021083514 -0.0196572100 -0.0185791047 -0.017787456
## b16a            -0.019892078 -0.0218696173 -0.0236920850 -0.025331012
## b18a             0.023588910  0.0247031036  0.0255310866  0.026130881
## c1              -0.003261323 -0.0107447997 -0.0160511808 -0.019482341
## smosttmedium     0.007781878  0.0143748671  0.0198925641  0.024521555
## smosttheavy      0.008369407  0.0188615609  0.0276980684  0.035129151
## policy_a1        0.001323079  0.0002564719 -0.0002893969 -0.000502695
## policy_a2       -0.011580535 -0.0095336537 -0.0078323045 -0.006491841
##                       5groups       6groups      7groups       8groups
## age_groupgr3039  0.0023082728  0.0028499769  0.003435992  0.0040652349
## age_groupgr4049 -0.0492204580 -0.0454919243 -0.041808878 -0.0382101617
## age_groupgr5059 -0.0848499046 -0.0797830184 -0.074773556 -0.0698546803
## age_group60plus -0.0587331396 -0.0523649773 -0.046133574 -0.0400706575
## d1a             -0.0271558212 -0.0228440585 -0.018953664 -0.0154489379
## educ22           0.0421981705  0.0396547208  0.037217175  0.0348898978
## educ23           0.1237989249  0.1212629615  0.118809501  0.1164560391
## ter_in2          0.0288544934  0.0270152733  0.025292217  0.0237279393
## ter_in3          0.0103677039  0.0083247489  0.006269863  0.0042497443
## selfhealth       0.0706970549  0.0691951011  0.067900557  0.0667719462
## h1              -0.0172302922 -0.0168642435 -0.016653073 -0.0165660642
## b16a            -0.0267628582 -0.0279691080 -0.028936452 -0.0296567771
## b18a             0.0265424083  0.0267913073  0.026892832  0.0268552808
## c1              -0.0213134307 -0.0217920759 -0.021137716 -0.0195409002
## smosttmedium     0.0284254962  0.0317447902  0.034597387  0.0370803803
## smosttheavy      0.0413823166  0.0466607936  0.051143311  0.0549848741
## policy_a1       -0.0005310473 -0.0004875677 -0.000456894 -0.0005007053
## policy_a2       -0.0055153556 -0.0048952793 -0.004614693 -0.0046481014
##                       9groups      10groups     11groups
## age_groupgr3039  0.0047336777  0.0054347439  0.006159504
## age_groupgr4049 -0.0347392171 -0.0314435986 -0.028374533
## age_groupgr5059 -0.0650627606 -0.0604378063 -0.056023850
## age_group60plus -0.0342117233 -0.0285969329 -0.023271812
## d1a             -0.0123018161 -0.0094889176 -0.006987929
## educ22           0.0326735764  0.0305651526  0.028557817
## educ23           0.1142153932  0.1120951688  0.110097250
## ter_in2          0.0223491894  0.0211716777  0.020203773
## ter_in3          0.0022980655  0.0004391681 -0.001309746
## selfhealth       0.0657700926  0.0648562173  0.063989677
## h1              -0.0165764354 -0.0166599949 -0.016794248
## b16a            -0.0301268306 -0.0303475763 -0.030323422
## b18a             0.0266826486  0.0263763904  0.025936263
## c1              -0.0171625509 -0.0141333718 -0.010553656
## smosttmedium     0.0392722063  0.0412353582  0.043019675
## smosttheavy      0.0583183172  0.0612565081  0.063895226
## policy_a1       -0.0006625225 -0.0009717927 -0.001447362
## policy_a2       -0.0049617275 -0.0055135566 -0.006253434
## 
##  
##  Confidence interval information ( 1000 bootstrap replicates, bty= perc ): 
## Relative Contributions with confidence intervals: 
##  
##                                       Lower  Upper
##                percentage 0.9         0.9    0.9   
## age_group.lmg  0.0201     ABCDE______ 0.0102 0.0515
## educ2.lmg      0.0374     ABC________ 0.0171 0.0689
## ter_in.lmg     0.0031     __CDEFGHIJ_ 0.0011 0.0212
## smostt.lmg     0.0053     __CDEFGHI__ 0.0021 0.0229
## policy_a.lmg   0.0003     ___DEFGHIJK 0.0006 0.0126
## d1a.lmg        0.0048     ___DEFGHIJ_ 0.0013 0.0166
## selfhealth.lmg 0.0255     ABCDE______ 0.0080 0.0540
## h1.lmg         0.0016     ___DEFGHIJK 0.0002 0.0133
## b16a.lmg       0.0019     ___DEFGHIJK 0.0002 0.0146
## b18a.lmg       0.0032     __CDEFGHIJK 0.0002 0.0173
## c1.lmg         0.0012     ____EFGHIJK 0.0006 0.0099
## 
## Letters indicate the ranks covered by bootstrap CIs. 
## (Rank bootstrap confidence intervals always obtained by percentile method) 
## CAUTION: Bootstrap confidence intervals can be somewhat liberal.

reg = lm(logC ~ c1+ter_in+age_group+educ2+selfhealth+smostt+policy_a, data=t2)
summary(reg)
## 
## Call:
## lm(formula = logC ~ c1 + ter_in + age_group + educ2 + selfhealth + 
##     smostt + policy_a, data = t2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55776 -0.14711 -0.00187  0.14897  0.52901 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      4.697343   0.043838 107.153  < 2e-16 ***
## c12             -0.008962   0.040115  -0.223  0.82332    
## ter_in2          0.020518   0.025860   0.793  0.42800    
## ter_in3         -0.004564   0.026111  -0.175  0.86132    
## age_groupgr3039  0.002269   0.031147   0.073  0.94196    
## age_groupgr4049 -0.033327   0.029619  -1.125  0.26118    
## age_groupgr5059 -0.057855   0.033655  -1.719  0.08637 .  
## age_group60plus -0.026090   0.048357  -0.540  0.58982    
## educ22           0.026184   0.028225   0.928  0.35413    
## educ23           0.112617   0.034579   3.257  0.00122 ** 
## selfhealthgood   0.064255   0.021373   3.006  0.00281 ** 
## smosttmedium     0.043157   0.033282   1.297  0.19547    
## smosttheavy      0.064494   0.034563   1.866  0.06277 .  
## policy_a1       -0.005284   0.023712  -0.223  0.82376    
## policy_a2       -0.005389   0.030000  -0.180  0.85753    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2076 on 404 degrees of freedom
## Multiple R-squared:  0.09842,    Adjusted R-squared:  0.06718 
## F-statistic:  3.15 on 14 and 404 DF,  p-value: 0.000104
anova(reg)
## Analysis of Variance Table
## 
## Response: logC
##             Df  Sum Sq Mean Sq F value   Pr(>F)   
## c1           1  0.0005 0.00053  0.0123 0.911640   
## ter_in       2  0.0895 0.04473  1.0377 0.355224   
## age_group    4  0.7226 0.18066  4.1909 0.002454 **
## educ2        2  0.5551 0.27755  6.4386 0.001768 **
## selfhealth   1  0.3794 0.37937  8.8006 0.003190 **
## smostt       2  0.1513 0.07564  1.7547 0.174282   
## policy_a     2  0.0028 0.00139  0.0323 0.968251   
## Residuals  404 17.4153 0.04311                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
par(mfrow=c(2,2))
plot(reg)

install.packages(“lsmeans”)

library(lsmeans)
## Warning: package 'lsmeans' was built under R version 3.2.5
## Loading required package: estimability
## Warning: package 'estimability' was built under R version 3.2.5
lsmeans(reg, "age_group")
##  age_group    lsmean         SE  df lower.CL upper.CL
##  group18-29 4.808900 0.02271738 404 4.764241 4.853559
##  gr3039     4.811170 0.03060186 404 4.751011 4.871328
##  gr4049     4.775574 0.02755691 404 4.721401 4.829746
##  gr5059     4.751045 0.03094551 404 4.690211 4.811880
##  60plus     4.782811 0.04712900 404 4.690162 4.875460
## 
## Results are averaged over the levels of: c1, ter_in, educ2, selfhealth, smostt, policy_a 
## Confidence level used: 0.95

educcation

lsmeans(reg, "educ2")
##  educ2   lsmean         SE  df lower.CL upper.CL
##  1     4.739633 0.02856822 404 4.683472 4.795794
##  2     4.765817 0.02267017 404 4.721251 4.810383
##  3     4.852250 0.02749980 404 4.798189 4.906310
## 
## Results are averaged over the levels of: c1, ter_in, age_group, selfhealth, smostt, policy_a 
## Confidence level used: 0.95

Selfhealth

lsmeans(reg, "selfhealth")
##  selfhealth   lsmean         SE  df lower.CL upper.CL
##  notwell    4.753772 0.02209456 404 4.710338 4.797207
##  good       4.818028 0.02310997 404 4.772597 4.863458
## 
## Results are averaged over the levels of: c1, ter_in, age_group, educ2, smostt, policy_a 
## Confidence level used: 0.95

Anti cam

lsmeans(reg, "policy_a")
##  policy_a   lsmean         SE  df lower.CL upper.CL
##  0        4.789458 0.02251976 404 4.745187 4.833728
##  1        4.784173 0.02408767 404 4.736821 4.831526
##  2        4.784069 0.03074085 404 4.723637 4.844501
## 
## Results are averaged over the levels of: c1, ter_in, age_group, educ2, selfhealth, smostt 
## Confidence level used: 0.95

prequency

lsmeans(reg, "smostt")
##  smostt   lsmean         SE  df lower.CL upper.CL
##  light  4.750016 0.02338176 404 4.704051 4.795981
##  medium 4.793174 0.02816266 404 4.737810 4.848537
##  heavy  4.814510 0.02852786 404 4.758429 4.870592
## 
## Results are averaged over the levels of: c1, ter_in, age_group, educ2, selfhealth, policy_a 
## Confidence level used: 0.95
  1. Binh Thang Ref: -Coppied: Prof Nguyen Van Tuan, (tuanvannguyen.blogspot.kr)