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/dataR2.dta")

r1 <- subset(r, costincrease <=150000)

attach(r1)

newdata2=r1

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, c1, c2, c23a, c3, c4, c5, c6, c7,
##     c8, c9, COST, cost1, cost2, 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, 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,
##     w1, w2, w3, w4

define varibles

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$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$trans_Y <- log10(newdata2$costincrease+1)

attach(newdata2)
## The following objects are masked from newdata2 (pos = 3):
## 
##     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, c1, c2, c23a, c3, c4, c5, c6, c7,
##     c8, c9, COST, cost1, cost2, 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, 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,
##     w1, w2, w3, w4
## 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, c1, c2, c23a, c3, c4, c5, c6, c7,
##     c8, c9, COST, cost1, cost2, 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, 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,
##     w1, w2, w3, w4
qqnorm(trans_Y )
qqline(trans_Y )

summary(trans_Y)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.301   4.301   4.602   4.551   4.778   5.176

re-organise our data by sampling .

newdata2=newdata2[sample(1:nrow(newdata2), 440, replace=F),]

Create new data frame (90%-10%) (N=440)

Train data

train=newdata2[1:308, ]
View(train)

Test data

test=newdata2[309:440, ]
View(test)

Install packages and library

library("brms")
## Warning: package 'brms' was built under R version 3.2.5
## Loading required package: Rcpp
## Warning: package 'Rcpp' was built under R version 3.2.5
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.2.5
## Loading 'brms' package (version 1.5.1). Useful instructions 
## can be found by typing help('brms'). A more detailed introduction 
## to the package is available through vignette('brms_overview').
library("caret")
## Warning: package 'caret' was built under R version 3.2.5
## Loading required package: lattice
library("coda")
## Warning: package 'coda' was built under R version 3.2.5
library("rstan", lib.loc="~/R/win-library/3.2")
## Warning: package 'rstan' was built under R version 3.2.5
## Loading required package: StanHeaders
## Warning: package 'StanHeaders' was built under R version 3.2.5
## rstan (Version 2.14.1, packaged: 2016-12-28 14:55:41 UTC, GitRev: 5fa1e80eb817)
## For execution on a local, multicore CPU with excess RAM we recommend calling
## rstan_options(auto_write = TRUE)
## options(mc.cores = parallel::detectCores())
## 
## Attaching package: 'rstan'
## The following object is masked from 'package:coda':
## 
##     traceplot
options(mc.cores = parallel::detectCores())

set up for fomulation

library("MCMCpack")
## Warning: package 'MCMCpack' was built under R version 3.2.5
## Loading required package: MASS
## ##
## ## Markov Chain Monte Carlo Package (MCMCpack)
## ## Copyright (C) 2003-2017 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
## ##
## ## Support provided by the U.S. National Science Foundation
## ## (Grants SES-0350646 and SES-0350613)
## ##
set.seed(1234) 
bayes.tobit <- MCMCtobit(trans_Y~age_group+h1+ d1a+educ2+ter_in+selfhealth+smostt
               +b16a+b18a+label1+anticam+noEnvi2, above = 150000, mcmc = 30000, verbose = 1000, data=train)
## 
## 
## MCMCtobit iteration 1 of 31000 
## beta = 
##    4.56899
##    0.02488
##   -0.00099
##   -0.06299
##   -0.23030
##   -0.09764
##   -0.00163
##    0.09593
##    0.24832
##    0.02890
##   -0.03906
##    0.04857
##   -0.02295
##    0.01341
##   -0.11670
##    0.03256
##   -0.08559
##    0.00484
##   -0.10560
## sigma2 =    0.11237
## 
## 
## MCMCtobit iteration 1001 of 31000 
## beta = 
##    4.35739
##   -0.06658
##   -0.02784
##   -0.11317
##   -0.15202
##   -0.06204
##    0.04460
##    0.05936
##    0.24458
##    0.00982
##    0.01747
##    0.16005
##    0.08980
##    0.04630
##   -0.02008
##    0.04063
##   -0.17386
##    0.13526
##   -0.05343
## sigma2 =    0.12833
## 
## 
## MCMCtobit iteration 2001 of 31000 
## beta = 
##    4.44477
##   -0.08082
##   -0.12908
##   -0.25250
##   -0.13886
##   -0.02180
##    0.00515
##    0.04748
##    0.17592
##   -0.03556
##   -0.01058
##    0.11186
##    0.03044
##    0.06334
##   -0.05316
##    0.21518
##   -0.05089
##    0.03241
##   -0.02808
## sigma2 =    0.10941
## 
## 
## MCMCtobit iteration 3001 of 31000 
## beta = 
##    4.38023
##   -0.02083
##   -0.07341
##   -0.17295
##   -0.21280
##   -0.09973
##    0.05683
##    0.11896
##    0.26317
##    0.07710
##   -0.03324
##    0.13499
##    0.12100
##    0.16430
##   -0.07396
##    0.02619
##   -0.03483
##    0.03715
##   -0.01178
## sigma2 =    0.11803
## 
## 
## MCMCtobit iteration 4001 of 31000 
## beta = 
##    4.45327
##    0.05839
##    0.10725
##    0.08394
##    0.03963
##   -0.08612
##   -0.02346
##    0.11437
##    0.23458
##    0.04112
##    0.02201
##    0.07993
##    0.08478
##    0.04969
##   -0.11675
##    0.02035
##   -0.13391
##    0.08037
##   -0.12981
## sigma2 =    0.10513
## 
## 
## MCMCtobit iteration 5001 of 31000 
## beta = 
##    4.43665
##   -0.12908
##   -0.15933
##   -0.20391
##   -0.36530
##   -0.07668
##    0.19824
##    0.09990
##    0.27036
##    0.00410
##   -0.02146
##    0.11792
##    0.10555
##    0.10247
##   -0.06726
##    0.05972
##   -0.08536
##   -0.01280
##   -0.12445
## sigma2 =    0.10621
## 
## 
## MCMCtobit iteration 6001 of 31000 
## beta = 
##    4.29130
##   -0.02499
##   -0.04714
##    0.05295
##   -0.15410
##    0.05088
##    0.05040
##    0.04340
##    0.25256
##    0.05797
##    0.04001
##    0.06969
##    0.12489
##    0.14364
##   -0.05068
##    0.10531
##   -0.11130
##    0.02563
##   -0.11430
## sigma2 =    0.10767
## 
## 
## MCMCtobit iteration 7001 of 31000 
## beta = 
##    4.45718
##   -0.07470
##   -0.16418
##   -0.15771
##   -0.17185
##    0.05197
##    0.06989
##    0.08223
##    0.18607
##    0.09751
##    0.01325
##    0.06443
##   -0.01025
##    0.05528
##   -0.05860
##    0.08870
##   -0.21853
##    0.12957
##   -0.10820
## sigma2 =    0.12273
## 
## 
## MCMCtobit iteration 8001 of 31000 
## beta = 
##    4.45387
##    0.03680
##    0.07987
##   -0.01887
##   -0.09005
##   -0.04031
##    0.02783
##    0.03755
##    0.22131
##   -0.06300
##   -0.08231
##    0.04669
##    0.11097
##    0.07835
##   -0.06534
##    0.11341
##   -0.14320
##    0.05511
##   -0.15860
## sigma2 =    0.11162
## 
## 
## MCMCtobit iteration 9001 of 31000 
## beta = 
##    4.41375
##    0.07167
##    0.07178
##    0.08711
##    0.01327
##   -0.00117
##   -0.05390
##    0.09232
##    0.21896
##    0.08253
##    0.01568
##    0.07989
##    0.03734
##    0.05774
##   -0.04035
##    0.04663
##   -0.17310
##    0.03219
##   -0.13766
## sigma2 =    0.12335
## 
## 
## MCMCtobit iteration 10001 of 31000 
## beta = 
##    4.54360
##   -0.00334
##   -0.00340
##   -0.09216
##   -0.12548
##   -0.05455
##    0.03760
##    0.02245
##    0.17966
##    0.07685
##   -0.02205
##    0.04995
##    0.06200
##   -0.00780
##   -0.11064
##    0.05017
##   -0.05057
##    0.06290
##   -0.06340
## sigma2 =    0.10333
## 
## 
## MCMCtobit iteration 11001 of 31000 
## beta = 
##    4.46445
##   -0.00004
##   -0.02352
##    0.00478
##   -0.08869
##    0.01028
##    0.08805
##    0.01808
##    0.22796
##   -0.00908
##   -0.05453
##    0.10802
##    0.01955
##   -0.02130
##   -0.16783
##    0.14046
##   -0.16196
##    0.16886
##   -0.01610
## sigma2 =    0.11864
## 
## 
## MCMCtobit iteration 12001 of 31000 
## beta = 
##    4.19063
##    0.04754
##   -0.00358
##    0.01367
##   -0.16134
##   -0.01581
##    0.00368
##    0.15284
##    0.32968
##    0.03757
##   -0.07855
##    0.11813
##    0.17807
##    0.14891
##    0.03087
##    0.08350
##   -0.18677
##    0.05636
##   -0.08914
## sigma2 =    0.12443
## 
## 
## MCMCtobit iteration 13001 of 31000 
## beta = 
##    4.59390
##   -0.07663
##   -0.06155
##   -0.08804
##   -0.18323
##    0.01029
##   -0.02361
##    0.08866
##    0.18965
##   -0.03478
##    0.11934
##    0.03795
##    0.01478
##    0.09278
##   -0.13729
##   -0.03621
##   -0.15701
##    0.07837
##   -0.09073
## sigma2 =    0.12801
## 
## 
## MCMCtobit iteration 14001 of 31000 
## beta = 
##    4.48978
##   -0.04370
##   -0.16385
##   -0.15097
##   -0.19528
##   -0.10905
##    0.04931
##    0.09127
##    0.19389
##    0.01445
##   -0.02679
##    0.07554
##    0.05233
##    0.08526
##   -0.00453
##    0.03431
##   -0.16300
##    0.00915
##   -0.11246
## sigma2 =    0.11026
## 
## 
## MCMCtobit iteration 15001 of 31000 
## beta = 
##    4.35004
##    0.01051
##    0.03644
##   -0.05259
##   -0.29856
##   -0.03542
##   -0.00005
##    0.13597
##    0.30693
##    0.02652
##   -0.03214
##    0.14437
##    0.12887
##    0.17799
##   -0.09911
##   -0.00699
##   -0.06190
##    0.06986
##    0.01263
## sigma2 =    0.12208
## 
## 
## MCMCtobit iteration 16001 of 31000 
## beta = 
##    4.46624
##    0.09155
##   -0.01486
##    0.01169
##   -0.11764
##   -0.03518
##   -0.00228
##    0.05932
##    0.25182
##   -0.01011
##   -0.10515
##    0.09077
##    0.06690
##    0.05848
##   -0.01517
##    0.02921
##   -0.23453
##    0.07716
##   -0.09279
## sigma2 =    0.10646
## 
## 
## MCMCtobit iteration 17001 of 31000 
## beta = 
##    4.52079
##   -0.00444
##   -0.09994
##   -0.17962
##   -0.29618
##   -0.00597
##    0.07980
##    0.07332
##    0.18753
##    0.00369
##   -0.06650
##    0.06450
##    0.05812
##    0.03431
##   -0.10315
##    0.05262
##   -0.16557
##    0.11646
##    0.00029
## sigma2 =    0.10459
## 
## 
## MCMCtobit iteration 18001 of 31000 
## beta = 
##    4.37324
##    0.07416
##   -0.13321
##   -0.00962
##   -0.15680
##    0.02660
##    0.02015
##    0.11334
##    0.16886
##    0.02186
##    0.05470
##    0.10283
##    0.04562
##    0.06281
##   -0.01140
##    0.04906
##   -0.09272
##    0.14970
##   -0.13794
## sigma2 =    0.11200
## 
## 
## MCMCtobit iteration 19001 of 31000 
## beta = 
##    4.28658
##   -0.07038
##   -0.00569
##   -0.00305
##   -0.25377
##   -0.02335
##    0.08695
##    0.09962
##    0.29063
##   -0.01559
##   -0.03440
##    0.08233
##   -0.01091
##    0.00034
##    0.08898
##    0.08365
##   -0.03288
##    0.03223
##   -0.22537
## sigma2 =    0.11760
## 
## 
## MCMCtobit iteration 20001 of 31000 
## beta = 
##    4.56803
##    0.10135
##    0.09110
##   -0.11760
##   -0.14052
##   -0.05940
##   -0.00948
##   -0.00087
##    0.22473
##   -0.08623
##   -0.09574
##    0.07891
##    0.14150
##    0.16415
##   -0.18164
##    0.04104
##   -0.11009
##    0.05317
##    0.04136
## sigma2 =    0.13376
## 
## 
## MCMCtobit iteration 21001 of 31000 
## beta = 
##    4.36429
##   -0.05203
##    0.01874
##   -0.01392
##   -0.01060
##    0.03516
##   -0.02238
##    0.09238
##    0.32159
##   -0.15749
##   -0.10057
##    0.10365
##    0.15161
##    0.16622
##   -0.06016
##    0.02806
##   -0.11605
##    0.05215
##   -0.13542
## sigma2 =    0.11841
## 
## 
## MCMCtobit iteration 22001 of 31000 
## beta = 
##    4.47952
##    0.04260
##   -0.12763
##   -0.05165
##   -0.24382
##   -0.06179
##    0.09511
##    0.07548
##    0.25811
##   -0.07684
##   -0.07327
##    0.02772
##    0.13279
##    0.08304
##   -0.07115
##    0.01340
##   -0.10517
##    0.10472
##   -0.14247
## sigma2 =    0.11882
## 
## 
## MCMCtobit iteration 23001 of 31000 
## beta = 
##    4.47407
##   -0.04559
##    0.00766
##   -0.09226
##   -0.21920
##   -0.18275
##    0.04631
##    0.02118
##    0.22101
##    0.02632
##   -0.09338
##    0.11497
##    0.11341
##    0.06604
##   -0.00081
##    0.01281
##   -0.15296
##    0.05286
##   -0.10098
## sigma2 =    0.10206
## 
## 
## MCMCtobit iteration 24001 of 31000 
## beta = 
##    4.42164
##   -0.00026
##   -0.04018
##   -0.13826
##   -0.09918
##   -0.02882
##    0.07926
##    0.05344
##    0.23806
##   -0.02546
##   -0.05729
##    0.16722
##    0.03654
##    0.14477
##   -0.04075
##   -0.01900
##   -0.16809
##    0.09957
##   -0.10923
## sigma2 =    0.11344
## 
## 
## MCMCtobit iteration 25001 of 31000 
## beta = 
##    4.34352
##   -0.03485
##   -0.05280
##   -0.06305
##   -0.11415
##   -0.00576
##    0.06118
##    0.11790
##    0.24276
##    0.00854
##   -0.02614
##    0.08794
##    0.11133
##    0.07884
##   -0.06882
##    0.03402
##   -0.10478
##    0.04650
##   -0.06701
## sigma2 =    0.11487
## 
## 
## MCMCtobit iteration 26001 of 31000 
## beta = 
##    4.56500
##   -0.08199
##   -0.27667
##   -0.23806
##   -0.19829
##   -0.03547
##    0.22181
##    0.02745
##    0.04517
##    0.03768
##   -0.05267
##    0.06923
##    0.02069
##   -0.03908
##   -0.07001
##    0.05106
##   -0.25734
##    0.13173
##   -0.10255
## sigma2 =    0.12336
## 
## 
## MCMCtobit iteration 27001 of 31000 
## beta = 
##    4.38376
##   -0.08126
##   -0.04905
##   -0.15730
##   -0.12093
##   -0.01602
##    0.07851
##    0.10537
##    0.20907
##    0.03690
##    0.02857
##    0.17731
##    0.07982
##    0.10422
##   -0.10032
##    0.03854
##   -0.08621
##   -0.00034
##   -0.07438
## sigma2 =    0.12415
## 
## 
## MCMCtobit iteration 28001 of 31000 
## beta = 
##    4.50493
##   -0.05824
##    0.07958
##   -0.01641
##   -0.02846
##   -0.00123
##    0.03734
##    0.17987
##    0.27724
##    0.03181
##   -0.00531
##    0.13013
##    0.04465
##   -0.03728
##   -0.09237
##   -0.04098
##   -0.15247
##   -0.00916
##   -0.04247
## sigma2 =    0.13854
## 
## 
## MCMCtobit iteration 29001 of 31000 
## beta = 
##    4.29775
##   -0.01763
##   -0.00768
##   -0.11391
##   -0.16345
##   -0.01786
##    0.06053
##    0.02076
##    0.18418
##    0.03454
##   -0.00188
##    0.05253
##    0.08954
##    0.04535
##    0.04520
##    0.10881
##   -0.16145
##    0.04876
##   -0.01065
## sigma2 =    0.10830
## 
## 
## MCMCtobit iteration 30001 of 31000 
## beta = 
##    4.63069
##   -0.13462
##   -0.12933
##   -0.10680
##   -0.16683
##   -0.08385
##    0.01057
##   -0.02132
##    0.09838
##    0.03941
##    0.04226
##    0.11720
##    0.08785
##    0.07890
##   -0.16106
##    0.05800
##   -0.17272
##    0.08323
##   -0.10192
## sigma2 =    0.10930
summary(bayes.tobit)
## 
## Iterations = 1001:31000
## Thinning interval = 1 
## Number of chains = 1 
## Sample size per chain = 30000 
## 
## 1. Empirical mean and standard deviation for each variable,
##    plus standard error of the mean:
## 
##                      Mean       SD  Naive SE Time-series SE
## (Intercept)      4.430606 0.098242 5.672e-04      5.672e-04
## age_groupgr3039 -0.019432 0.070342 4.061e-04      4.107e-04
## age_groupgr4049 -0.038693 0.073946 4.269e-04      4.269e-04
## age_groupgr5059 -0.081334 0.085307 4.925e-04      4.977e-04
## age_group60plus -0.163759 0.104571 6.037e-04      6.037e-04
## h12             -0.036086 0.044088 2.545e-04      2.545e-04
## d1amarried       0.052952 0.061618 3.558e-04      3.558e-04
## educ22           0.067866 0.057073 3.295e-04      3.295e-04
## educ23           0.214069 0.069754 4.027e-04      4.027e-04
## ter_in2          0.007316 0.051779 2.989e-04      2.989e-04
## ter_in3         -0.019013 0.052154 3.011e-04      3.011e-04
## selfhealthgood   0.099041 0.042196 2.436e-04      2.436e-04
## smosttmedium     0.069675 0.052550 3.034e-04      3.034e-04
## smosttheavy      0.060141 0.056076 3.238e-04      3.238e-04
## b16a1           -0.056816 0.062936 3.634e-04      3.634e-04
## b18abad          0.051333 0.044017 2.541e-04      2.541e-04
## label11         -0.133114 0.062535 3.610e-04      3.610e-04
## anticam          0.067007 0.054075 3.122e-04      3.161e-04
## noEnvi2         -0.079353 0.052643 3.039e-04      3.039e-04
## sigma2           0.115144 0.009936 5.736e-05      6.173e-05
## 
## 2. Quantiles for each variable:
## 
##                     2.5%      25%       50%       75%    97.5%
## (Intercept)      4.23717  4.36479  4.430717  4.496180  4.62485
## age_groupgr3039 -0.15647 -0.06666 -0.019485  0.027709  0.11958
## age_groupgr4049 -0.18366 -0.08833 -0.038654  0.011141  0.10628
## age_groupgr5059 -0.24856 -0.13919 -0.080502 -0.024024  0.08541
## age_group60plus -0.36980 -0.23434 -0.163507 -0.093475  0.04001
## h12             -0.12162 -0.06583 -0.036417 -0.006173  0.05076
## d1amarried      -0.06679  0.01101  0.052808  0.094557  0.17364
## educ22          -0.04321  0.02930  0.067822  0.106401  0.18003
## educ23           0.07712  0.16708  0.214089  0.261200  0.34985
## ter_in2         -0.09444 -0.02761  0.007389  0.041726  0.11021
## ter_in3         -0.12196 -0.05392 -0.018950  0.015661  0.08307
## selfhealthgood   0.01566  0.07076  0.099003  0.127609  0.18235
## smosttmedium    -0.03354  0.03432  0.069574  0.104927  0.17310
## smosttheavy     -0.04940  0.02236  0.060313  0.097560  0.17031
## b16a1           -0.18231 -0.09883 -0.056477 -0.014555  0.06665
## b18abad         -0.03511  0.02192  0.051223  0.080904  0.13841
## label11         -0.25618 -0.17545 -0.133333 -0.090160 -0.01109
## anticam         -0.03801  0.03096  0.066737  0.102775  0.17343
## noEnvi2         -0.18325 -0.11463 -0.079584 -0.043858  0.02323
## sigma2           0.09744  0.10816  0.114578  0.121400  0.13599

summary(bayes.tobit) bayes.tobit$fit

prob=as.data.frame(predict(bayes.tobit ,test,type=“response”))

library(e1071) pred=ifelse(prob$Estimate> 0.5, 1, 0)




##Results

confusionMatrix(data=pred,reference=test$costincrease) ```