library("foreign", lib.loc="~/R/win-library/3.2")
## Warning: package 'foreign' was built under R version 3.2.5
library(WRS2)
## Warning: package 'WRS2' was built under R version 3.2.5
##data for DEE
df=read.csv("C:/Users/BINH THANG/Dropbox/R - Learning/drbinh/2017/slieubieudo.csv")
##data for type 2 EEL (graph 2 cua anh)
df1=read.csv("C:/Users/BINH THANG/Dropbox/R - Learning/drbinh/2017/bieudo2.csv")
formula1="Preb~nhom1"
yuen(formula=formula1, data=df,tr = 0.2)
## Call:
## yuen(formula = formula1, data = df, tr = 0.2)
##
## Test statistic: 3.2208 (df = 9.82), p-value = 0.00937
##
## Trimmed mean difference: 12.51978
## 95 percent confidence interval:
## 3.8373 21.2023
yuenbt(formula1, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula1, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 3.1376 (df = NA), p-value = 0.016
##
## Trimmed mean difference: 12.51978
## 95 percent confidence interval:
## 3.3817 21.6578
formula2="e30days~nhom1"
yuen(formula=formula2, data=df,tr = 0.2)
## Call:
## yuen(formula = formula2, data = df, tr = 0.2)
##
## Test statistic: 2.7358 (df = 9.58), p-value = 0.02177
##
## Trimmed mean difference: 11.65476
## 95 percent confidence interval:
## 2.1065 21.2031
yuenbt(formula2, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula2, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 2.6841 (df = NA), p-value = 0.024
##
## Trimmed mean difference: 11.65476
## 95 percent confidence interval:
## 2.0994 21.2101
formula4="e6months~nhom1"
yuen(formula=formula4, data=df,tr = 0.2)
## Call:
## yuen(formula = formula4, data = df, tr = 0.2)
##
## Test statistic: 2.6951 (df = 13.1), p-value = 0.01826
##
## Trimmed mean difference: 12.41714
## 95 percent confidence interval:
## 2.4716 22.3626
yuenbt(formula4, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula4, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 2.2934 (df = NA), p-value = 0.023
##
## Trimmed mean difference: 12.41714
## 95 percent confidence interval:
## 2.3435 22.4908
formula5="e1year~nhom1"
yuen(formula=formula5, data=df,tr = 0.2)
## Call:
## yuen(formula = formula5, data = df, tr = 0.2)
##
## Test statistic: 2.4129 (df = 3.62), p-value = 0.08002
##
## Trimmed mean difference: 18.825
## 95 percent confidence interval:
## -3.7576 41.4076
yuenbt(formula5, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula5, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 1.491 (df = NA), p-value = 0.206
##
## Trimmed mean difference: 18.825
## 95 percent confidence interval:
## -18.6409 56.2909
formula6="e2years~nhom1"
yuen(formula=formula6, data=df,tr = 0.2)
## Call:
## yuen(formula = formula6, data = df, tr = 0.2)
##
## Test statistic: 0.4024 (df = 9.52), p-value = 0.6963
##
## Trimmed mean difference: 2.85
## 95 percent confidence interval:
## -13.0412 18.7412
yuenbt(formula6, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula6, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.2879 (df = NA), p-value = 0.691
##
## Trimmed mean difference: 2.85
## 95 percent confidence interval:
## -15.3851 21.0851
formula7="e3years~nhom1"
yuen(formula=formula7, data=df,tr = 0.2)
## Call:
## yuen(formula = formula7, data = df, tr = 0.2)
##
## Test statistic: 0.6719 (df = 4.97), p-value = 0.53164
##
## Trimmed mean difference: 6.20833
## 95 percent confidence interval:
## -17.5936 30.0102
yuenbt(formula7, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula7, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.6757 (df = NA), p-value = 0.538
##
## Trimmed mean difference: 6.20833
## 95 percent confidence interval:
## -17.4599 29.8766
formula8="e4years~nhom1"
yuen(formula=formula8, data=df,tr = 0.2)
## Call:
## yuen(formula = formula8, data = df, tr = 0.2)
##
## Test statistic: 2.7718 (df = 3.12), p-value = 0.06642
##
## Trimmed mean difference: 23.08667
## 95 percent confidence interval:
## -2.8476 49.021
yuenbt(formula8, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula8, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 2.8619 (df = NA), p-value = 0.049
##
## Trimmed mean difference: 23.08667
## 95 percent confidence interval:
## 0.1908 45.9825
formula9="e5years~nhom1"
yuen(formula=formula9, data=df,tr = 0.2)
## Call:
## yuen(formula = formula9, data = df, tr = 0.2)
##
## Test statistic: 0.8589 (df = 5.7), p-value = 0.42506
##
## Trimmed mean difference: 12.72667
## 95 percent confidence interval:
## -24.0019 49.4552
yuenbt(formula9, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula9, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.6126 (df = NA), p-value = 0.42
##
## Trimmed mean difference: 12.72667
## 95 percent confidence interval:
## -28.6923 54.1456
formula10="e6years~nhom1"
yuen(formula=formula10, data=df,tr = 0.2)
## Call:
## yuen(formula = formula10, data = df, tr = 0.2)
##
## Test statistic: 1.8541 (df = 3.85), p-value = 0.14016
##
## Trimmed mean difference: 36.3
## 95 percent confidence interval:
## -18.9162 91.5162
yuenbt(formula10, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula10, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 1.1124 (df = NA), p-value = 0.155
##
## Trimmed mean difference: 36.3
## 95 percent confidence interval:
## -26.6172 99.2172
formula11="e7years~nhom1"
yuen(formula=formula11, data=df,tr = 0.2)
## Call:
## yuen(formula = formula11, data = df, tr = 0.2)
##
## Test statistic: 0.5752 (df = 4.03), p-value = 0.59576
##
## Trimmed mean difference: 11.59167
## 95 percent confidence interval:
## -44.1874 67.3707
yuenbt(formula11, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula11, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.3451 (df = NA), p-value = 0.583
##
## Trimmed mean difference: 11.59167
## 95 percent confidence interval:
## -74.4915 97.6748
formula12="e8years~nhom1"
yuen(formula=formula12, data=df,tr = 0.2)
## Call:
## yuen(formula = formula12, data = df, tr = 0.2)
##
## Test statistic: NA (df = NA), p-value = NA
##
## Trimmed mean difference: 32
## 95 percent confidence interval:
## NA NA
yuenbt(formula12, data=df, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula12, data = df, tr = 0.2, nboot = 1000)
##
## Test statistic: NA (df = NA), p-value = 0
##
## Trimmed mean difference: 32
## 95 percent confidence interval:
## NA NA
#formula="e11y~nhom1"
#yuen(formula=formula, data=df,tr = 0.2)
#yuenbt(formula, data=df, tr = 0.2, nboot = 1000)
P-value for 2nd
df1=read.csv("C:/Users/BINH THANG/Dropbox/R - Learning/drbinh/2017/bieudo2.csv")
formula1="Preb~nhom1"
yuen(formula=formula1, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula1, data = df1, tr = 0.2)
##
## Test statistic: 2.3912 (df = 2.25), p-value = 0.12514
##
## Trimmed mean difference: 14.53333
## 95 percent confidence interval:
## -9.0054 38.0721
yuenbt(formula1, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula1, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 2.5934 (df = NA), p-value = 0.282
##
## Trimmed mean difference: 14.53333
## 95 percent confidence interval:
## -19.67 48.7366
formula2="e30days~nhom1"
yuen(formula=formula2, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula2, data = df1, tr = 0.2)
##
## Test statistic: 2.7081 (df = 2.5), p-value = 0.08947
##
## Trimmed mean difference: 13.80333
## 95 percent confidence interval:
## -4.4301 32.0368
yuenbt(formula2, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula2, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 2.9279 (df = NA), p-value = 0.132
##
## Trimmed mean difference: 13.80333
## 95 percent confidence interval:
## -5.7801 33.3867
formula4="e6months~nhom1"
yuen(formula=formula4, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula4, data = df1, tr = 0.2)
##
## Test statistic: 2.919 (df = 3.36), p-value = 0.05361
##
## Trimmed mean difference: 12.8875
## 95 percent confidence interval:
## -0.3515 26.1265
yuenbt(formula4, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula4, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 3.0502 (df = NA), p-value = 0.043
##
## Trimmed mean difference: 12.8875
## 95 percent confidence interval:
## 0.747 25.028
formula5="e1year~nhom1"
yuen(formula=formula5, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula5, data = df1, tr = 0.2)
##
## Test statistic: 4.4309 (df = 1.76), p-value = 0.05965
##
## Trimmed mean difference: 14.84444
## 95 percent confidence interval:
## -1.6649 31.3538
yuenbt(formula5, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula5, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 2.8585 (df = NA), p-value = 0.064
##
## Trimmed mean difference: 14.84444
## 95 percent confidence interval:
## -1.6705 31.3594
formula6="e2years~nhom1"
yuen(formula=formula6, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula6, data = df1, tr = 0.2)
##
## Test statistic: 0.9448 (df = 3.45), p-value = 0.40608
##
## Trimmed mean difference: 4.56667
## 95 percent confidence interval:
## -9.7363 18.8696
yuenbt(formula6, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula6, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.6226 (df = NA), p-value = 0.446
##
## Trimmed mean difference: 4.56667
## 95 percent confidence interval:
## -21.7489 30.8822
formula7="e3years~nhom1"
yuen(formula=formula7, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula7, data = df1, tr = 0.2)
##
## Test statistic: 0.8947 (df = 3.46), p-value = 0.42886
##
## Trimmed mean difference: 8.475
## 95 percent confidence interval:
## -19.5392 36.4892
yuenbt(formula7, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula7, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.5368 (df = NA), p-value = 0.395
##
## Trimmed mean difference: 8.475
## 95 percent confidence interval:
## -27.8464 44.7964
formula8="e4years~nhom1"
yuen(formula=formula8, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula8, data = df1, tr = 0.2)
##
## Test statistic: NA (df = NA), p-value = NA
##
## Trimmed mean difference: 13.425
## 95 percent confidence interval:
## NA NA
yuenbt(formula8, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula8, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: NA (df = NA), p-value = 0
##
## Trimmed mean difference: 13.425
## 95 percent confidence interval:
## NA NA
formula9="e5years~nhom1"
yuen(formula=formula9, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula9, data = df1, tr = 0.2)
##
## Test statistic: 0.5126 (df = 3.49), p-value = 0.63892
##
## Trimmed mean difference: 5.94167
## 95 percent confidence interval:
## -28.175 40.0583
yuenbt(formula9, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula9, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: 0.3076 (df = NA), p-value = 0.618
##
## Trimmed mean difference: 5.94167
## 95 percent confidence interval:
## -26.9952 38.8785
formula10="e6years~nhom1"
yuen(formula=formula10, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula10, data = df1, tr = 0.2)
##
## Test statistic: NA (df = NA), p-value = NA
##
## Trimmed mean difference: 32.25
## 95 percent confidence interval:
## NA NA
yuenbt(formula10, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula10, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: NA (df = NA), p-value = 0
##
## Trimmed mean difference: 32.25
## 95 percent confidence interval:
## NA NA
formula11="e7years~nhom1"
yuen(formula=formula11, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula11, data = df1, tr = 0.2)
##
## Test statistic: NA (df = NA), p-value = NA
##
## Trimmed mean difference: 21.225
## 95 percent confidence interval:
## NA NA
yuenbt(formula11, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula11, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: NA (df = NA), p-value = 0
##
## Trimmed mean difference: 21.225
## 95 percent confidence interval:
## NA NA
formula12="e8years~nhom1"
yuen(formula=formula12, data=df1,tr = 0.2)
## Call:
## yuen(formula = formula12, data = df1, tr = 0.2)
##
## Test statistic: NA (df = NA), p-value = NA
##
## Trimmed mean difference: 32
## 95 percent confidence interval:
## NA NA
yuenbt(formula12, data=df1, tr = 0.2, nboot = 1000)
## Call:
## yuenbt(formula = formula12, data = df1, tr = 0.2, nboot = 1000)
##
## Test statistic: NA (df = NA), p-value = 0
##
## Trimmed mean difference: 32
## 95 percent confidence interval:
## NA NA
library(reshape2)
## Warning: package 'reshape2' was built under R version 3.2.5
names(df)
## [1] "stt" "ID" "Preb" "e30days" "e6months" "e1year"
## [7] "e2years" "e3years" "e4years" "e5years" "e6years" "e7years"
## [13] "e8years" "e11y" "gd" "nhom1"
d<- melt(df, id.vars = c("ID", "nhom1"), measure.vars = c( "Preb","e30days", "e6months", "e1year","e2years" , "e3years" , "e4years" , "e5years" ,"e6years" , "e7years" ,"e8years" ),variable.name = "time")
d$time1=as.numeric(d$time)
d=na.omit(d)
$p for trend using robus regression
library(MASS)
#p chung cho ca 2 nhom
a1=rlm(d$value~ d$time1+d$nhom1)
summary(a1)
##
## Call: rlm(formula = d$value ~ d$time1 + d$nhom1)
## Residuals:
## Min 1Q Median 3Q Max
## -35.0579 -7.7703 -0.4385 7.5199 57.3713
##
## Coefficients:
## Value Std. Error t value
## (Intercept) 71.6606 2.4830 28.8610
## d$time1 0.1097 0.3903 0.2812
## d$nhom1 -14.1141 2.1852 -6.4589
##
## Residual standard error: 11.51 on 170 degrees of freedom
a1=rlm(d$value~ d$time1+d$nhom1)
summary(a1)
##
## Call: rlm(formula = d$value ~ d$time1 + d$nhom1)
## Residuals:
## Min 1Q Median 3Q Max
## -35.0579 -7.7703 -0.4385 7.5199 57.3713
##
## Coefficients:
## Value Std. Error t value
## (Intercept) 71.6606 2.4830 28.8610
## d$time1 0.1097 0.3903 0.2812
## d$nhom1 -14.1141 2.1852 -6.4589
##
## Residual standard error: 11.51 on 170 degrees of freedom
#p trend cho nhom 11 cases (late?)
d1=subset(d, nhom1==0)
a2=lm(value~ time1, data=d1)
summary(a2)
##
## Call:
## lm(formula = value ~ time1, data = d1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -39.964 -10.424 -0.981 8.544 54.496
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 69.7972 4.2304 16.499 <2e-16 ***
## time1 0.7867 0.7728 1.018 0.313
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.41 on 62 degrees of freedom
## Multiple R-squared: 0.01644, Adjusted R-squared: 0.0005759
## F-statistic: 1.036 on 1 and 62 DF, p-value: 0.3126
#p trend cho nhom 22 cases (early)
d2=subset(d, nhom1==1)
a3=lm(value~ time1, data=d2)
summary(a3)
##
## Call:
## lm(formula = value ~ time1, data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.392 -7.171 -0.879 7.021 34.008
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 59.2664 2.0960 28.276 <2e-16 ***
## time1 -0.2974 0.4603 -0.646 0.52
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.94 on 107 degrees of freedom
## Multiple R-squared: 0.003887, Adjusted R-squared: -0.005422
## F-statistic: 0.4175 on 1 and 107 DF, p-value: 0.5195
#Overall, it's shown p=0.634, which indicated no significant trend increasing or decreasing. However, we found statistical significantly diffirence in 2 groups (p=9.47e-10)
#In particualr, no significant was observed in both groups (p=0.0.313 , p=0.52, respectively)
d00<- melt(df1, id.vars = c("stt", "nhom1"), measure.vars = c( "Preb","e30days", "e6months", "e1year","e2years" , "e3years" , "e4years" , "e5years" ,"e6years" , "e7years" ,"e8years" ),variable.name = "time")
d00$time1=as.numeric(d00$time)
d00=na.omit(d00)
a=rlm(d00$value~ d00$time1+d00$nhom1, data=d00)
summary(a)
##
## Call: rlm(formula = d00$value ~ d00$time1 + d00$nhom1, data = d00)
## Residuals:
## Min 1Q Median 3Q Max
## -21.893 -5.554 0.151 5.549 36.507
##
## Coefficients:
## Value Std. Error t value
## (Intercept) 70.9101 2.2703 31.2340
## d00$time1 -0.3458 0.3259 -1.0610
## d00$nhom1 -13.6592 2.0248 -6.7460
##
## Residual standard error: 8.266 on 115 degrees of freedom
a=lm(d00$value~ d00$time1+d00$nhom1)
summary(a)
##
## Call:
## lm(formula = d00$value ~ d00$time1 + d00$nhom1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -22.498 -5.427 0.145 5.907 35.902
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 69.7929 2.4636 28.329 < 2e-16 ***
## d00$time1 -0.2730 0.3537 -0.772 0.442
## d00$nhom1 -12.6648 2.1972 -5.764 7.01e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.35 on 115 degrees of freedom
## Multiple R-squared: 0.2245, Adjusted R-squared: 0.2111
## F-statistic: 16.65 on 2 and 115 DF, p-value: 4.461e-07
#it's shown p=0.44, which indicated no significant trend increasing or decreasing. However, we found statistical significantly diffirence in 2 groups (p=7.01e-08). However, ... significant dif between 2 gorups
#p trend cho nhom 11 cases (late?)
d2=subset(d00, nhom1==0)
a2=lm(value~ time1, data=d00)
summary(a2)
##
## Call:
## lm(formula = value ~ time1, data = d00)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.759 -7.771 -0.946 6.208 31.641
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 59.63395 1.94583 30.647 <2e-16 ***
## time1 -0.09751 0.39832 -0.245 0.807
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.7 on 116 degrees of freedom
## Multiple R-squared: 0.0005164, Adjusted R-squared: -0.0081
## F-statistic: 0.05993 on 1 and 116 DF, p-value: 0.807
#p trend cho nhom 22 cases (early)
d2=subset(d00, nhom1==1)
a3=lm(value~ time1, data=d2)
summary(a3)
##
## Call:
## lm(formula = value ~ time1, data = d2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.827 -5.450 0.047 4.521 36.573
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 57.5626 2.0657 27.866 <2e-16 ***
## time1 -0.3835 0.4377 -0.876 0.383
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.72 on 86 degrees of freedom
## Multiple R-squared: 0.008849, Adjusted R-squared: -0.002676
## F-statistic: 0.7679 on 1 and 86 DF, p-value: 0.3833
#Conclusion: no significant was observed in both groups (p=0.807 , p=0.383respectively