PHÂN TÍCH CÁC YẾU TỐ ĐÔNG MÁU

library(factoextra)
## Warning: package 'factoextra' was built under R version 4.3.2
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## Warning: package 'stringr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ✔ readr     2.1.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(rstanarm)
## Loading required package: Rcpp
## This is rstanarm version 2.26.1
## - See https://mc-stan.org/rstanarm/articles/priors for changes to default priors!
## - Default priors may change, so it's safest to specify priors, even if equivalent to the defaults.
## - For execution on a local, multicore CPU with excess RAM we recommend calling
##   options(mc.cores = parallel::detectCores())
library(BAS)
## Warning: package 'BAS' was built under R version 4.3.2
library(broom)
library(GGally)
## Warning: package 'GGally' was built under R version 4.3.2
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
library(table1)
## 
## Attaching package: 'table1'
## 
## The following objects are masked from 'package:base':
## 
##     units, units<-

Gọi số liệu

dongmau = read.csv("E:\\OneDrive - UMP\\R - lenh 2016\\dongmau.csv", header=T)
head(dongmau)
##   ID   MSBN               HOTENBN gioi  nam tuoi   chandoan tcks tckpt  tck1st
## 1 62 758008    TR?N TH? M? C\xdaC   nu 1996   27 binhthuong 27.5  0.90 368.229
## 2 63 758756    PH?M TH? LAN H??NG   nu 1991   32 binhthuong 35.7  1.16 337.741
## 3 74 715955     NGUY?N TH? T\xc1M   nu 1958   65 binhthuong 33.5  1.12 226.970
## 4 75 710555 NGUY?N TH? NH? \xc1NH   nu 1998   25 binhthuong 32.4  1.08 265.239
## 5 76 202001                  LINH   nu 2001   22 binhthuong 32.4  1.08 357.583
## 6 78 202020        B\xcdCH PH??NG   nu 2000   23 binhthuong 29.0  0.97 299.362
##    tck2nd  tckDER
## 1 953.763 415.402
## 2 722.137 386.756
## 3 691.490 285.098
## 4 686.452 306.556
## 5 895.965 458.423
## 6 957.451 413.032
attach(dongmau)
names(dongmau)
##  [1] "ID"       "MSBN"     "HOTENBN"  "gioi"     "nam"      "tuoi"    
##  [7] "chandoan" "tcks"     "tckpt"    "tck1st"   "tck2nd"   "tckDER"

Gọi thư viện

library(table1)
table1(~ tcks + tckpt + tck1st + tck2nd + tckDER | chandoan,
       data = dongmau, transpose = F)
binhthuong
(N=32)
shocknhiemtrung
(N=33)
xogan
(N=28)
Overall
(N=93)
tcks
Mean (SD) 31.1 (2.99) 32.1 (2.84) 31.6 (3.00) 31.6 (2.94)
Median [Min, Max] 31.2 [26.0, 36.7] 32.3 [26.4, 36.7] 31.4 [27.4, 38.3] 31.7 [26.0, 38.3]
tckpt
Mean (SD) 1.02 (0.0973) 1.06 (0.0963) 1.04 (0.101) 1.04 (0.0985)
Median [Min, Max] 1.03 [0.850, 1.20] 1.06 [0.870, 1.22] 1.03 [0.890, 1.25] 1.05 [0.850, 1.25]
tck1st
Mean (SD) 283 (66.0) 394 (160) 281 (133) 322 (136)
Median [Min, Max] 270 [188, 545] 362 [127, 850] 253 [112, 703] 295 [112, 850]
tck2nd
Mean (SD) 776 (144) 1070 (427) 822 (314) 895 (342)
Median [Min, Max] 751 [487, 1030] 1050 [294, 2310] 762 [359, 1630] 854 [294, 2310]
tckDER
Mean (SD) 349 (74.0) 334 (146) 299 (137) 329 (123)
Median [Min, Max] 344 [210, 592] 322 [89.5, 809] 291 [118, 695] 322 [89.5, 809]
# Phân tích

library(nnet);
require(brms)
## Loading required package: brms
## Warning: package 'brms' was built under R version 4.3.2
## Loading 'brms' package (version 2.20.4). Useful instructions
## can be found by typing help('brms'). A more detailed introduction
## to the package is available through vignette('brms_overview').
## 
## Attaching package: 'brms'
## The following objects are masked from 'package:rstanarm':
## 
##     dirichlet, exponential, get_y, lasso, ngrps
## The following object is masked from 'package:stats':
## 
##     ar
  m.2 = multinom(tckDER ~ chandoan*gioi, data=dongmau)
## # weights:  651 (552 variable)
## initial  value 421.531753 
## iter  10 value 260.126096
## iter  20 value 255.529734
## iter  30 value 255.507652
## final  value 255.507626 
## converged
 summary(m.2)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## multinom(formula = tckDER ~ chandoan * gioi, data = dongmau)
## 
## Coefficients:
##         (Intercept) chandoanshocknhiemtrung chandoanxogan     gioinu
## 103.975 -30.8582378                7.582747     -12.43298   1.337643
## 108.516 -30.8580446                7.582940     -12.43298   1.337836
## 118.037  -0.9740867              -14.112900      49.72905 -24.541018
## 119.016  -0.9740867              -14.112900      49.72905 -24.541018
## 138.995  -0.9740867              -14.112900      49.72905 -24.541018
## 154.745 -19.9765006              -14.399264      22.94473  14.455573
## 166.358  -0.9740867              -14.112900      49.72905 -24.541018
## 180.441 -19.9765008              -14.399264      22.94473  14.455573
## 182.349  -5.2749156               42.528930     -12.43184 -32.075827
## 199.119 -19.9765006              -14.399264      22.94473  14.455573
## 201.211 -19.9765005              -14.399264      22.94473  14.455573
## 209.545  -5.2771144              -26.760810     -16.82552  36.155279
## 210.187  -5.2749156               42.528930     -12.43184 -32.075827
## 223.049 -19.9765006              -14.399264      22.94473  14.455573
## 223.836 -30.8591048                7.581880     -12.43298   1.336776
## 229.404  -5.2749156               42.528930     -12.43184 -32.075827
## 236.528 -30.8590794                7.581905     -12.43298   1.336801
## 240.058 -30.8588916                7.582093     -12.43298   1.336989
## 248.788 -19.9765008              -14.399264      22.94473  14.455573
## 251.811  -5.2749156               42.528930     -12.43184 -32.075827
## 253.377  -0.9740867              -14.112900      49.72905 -24.541018
## 256.451  -5.2771144              -26.760810     -16.82552  36.155279
## 256.623 -19.9765006              -14.399264      22.94473  14.455573
## 259.216 -30.8590928                7.581892     -12.43298   1.336788
## 261.591  36.2670849              -24.173918     -20.81695 -30.187547
## 273.706 -30.8590225                7.581962     -12.43298   1.336858
## 274.221  -5.2749156               42.528930     -12.43184 -32.075827
## 277.902  -5.2771144              -26.760810     -16.82552  36.155279
## 285.098  -5.2771144              -26.760810     -16.82552  36.155279
## 285.398  36.2670849              -24.173918     -20.81695 -30.187547
## 287.85   -0.9740867              -14.112900      49.72905 -24.541018
## 290.612  -0.9740867              -14.112900      49.72905 -24.541018
## 290.641 -30.8590051                7.581980     -12.43298   1.336876
## 290.785  36.2670849              -24.173918     -20.81695 -30.187547
## 291.173 -19.9765008              -14.399264      22.94473  14.455573
## 291.557 -19.9765008              -14.399264      22.94473  14.455573
## 294.762  -5.2771144              -26.760810     -16.82552  36.155279
## 297.156  36.2670849              -24.173918     -20.81695 -30.187547
## 305.073  -0.9740867              -14.112900      49.72905 -24.541018
## 305.565  36.2670849              -24.173918     -20.81695 -30.187547
## 306.556  -5.2771145              -26.760810     -16.82552  36.155279
## 312.464  36.2670849              -24.173918     -20.81695 -30.187547
## 312.797  -5.2749156               42.528930     -12.43184 -32.075827
## 312.808 -30.8590696                7.581915     -12.43298   1.336811
## 314.154  -0.9740867              -14.112900      49.72905 -24.541018
## 321.9   -30.8585392                7.582446     -12.43298   1.337341
## 322.317  36.2670849              -24.173918     -20.81695 -30.187547
## 327.601 -19.9765009              -14.399264      22.94473  14.455573
## 328.973  -5.2749157               42.528930     -12.43184 -32.075827
## 330.333 -19.9765007              -14.399264      22.94473  14.455573
## 330.903  -5.2771144              -26.760810     -16.82552  36.155279
## 331.837  -0.9740867              -14.112900      49.72905 -24.541018
## 332.761  36.2670849              -24.173918     -20.81695 -30.187547
## 334.469  -0.9740867              -14.112900      49.72905 -24.541018
## 339.945  36.2670849              -24.173918     -20.81695 -30.187547
## 340.431 -30.8591480                7.581837     -12.43298   1.336733
## 347.8    36.2670849              -24.173918     -20.81695 -30.187547
## 349.491  -5.2771145              -26.760810     -16.82552  36.155279
## 350.981  36.2670849              -24.173918     -20.81695 -30.187547
## 356.414 -19.9765009              -14.399264      22.94473  14.455573
## 357.809  -5.2771144              -26.760810     -16.82552  36.155279
## 360.229  36.2670849              -24.173918     -20.81695 -30.187547
## 362.996  36.2670849              -24.173918     -20.81695 -30.187547
## 366.093  -5.2749156               42.528930     -12.43184 -32.075827
## 369.956 -30.8591615                7.581823     -12.43298   1.336719
## 374.278  36.2670849              -24.173918     -20.81695 -30.187547
## 377.571  -5.2749156               42.528930     -12.43184 -32.075827
## 378.873 -30.8587061                7.582279     -12.43298   1.337175
## 381.608  -5.2749156               42.528930     -12.43184 -32.075827
## 386.756  -5.2771145              -26.760810     -16.82552  36.155279
## 387.685  -5.2771145              -26.760810     -16.82552  36.155279
## 388.897  -5.2749156               42.528930     -12.43184 -32.075827
## 393.754 -30.8587078                7.582277     -12.43298   1.337173
## 398.638  -5.2749156               42.528930     -12.43184 -32.075827
## 401.292 -19.9765007              -14.399264      22.94473  14.455573
## 406.177  -5.2771144              -26.760810     -16.82552  36.155279
## 413.032  -5.2771145              -26.760810     -16.82552  36.155279
## 415.402  -5.2771145              -26.760810     -16.82552  36.155279
## 427.158  -5.2771144              -26.760810     -16.82552  36.155279
## 458.423  -5.2771144              -26.760810     -16.82552  36.155279
## 460.808  36.2670849              -24.173918     -20.81695 -30.187547
## 462.363 -30.8598983                7.581087     -12.43298   1.335982
## 465.134  -5.2749157               42.528930     -12.43184 -32.075827
## 476.553  -0.9740867              -14.112900      49.72905 -24.541018
## 476.743  -5.2749156               42.528930     -12.43184 -32.075827
## 496.612  -0.9740867              -14.112900      49.72905 -24.541018
## 563.558 -30.8585392                7.582446     -12.43298   1.337341
## 590.747 -19.9765007              -14.399264      22.94473  14.455573
## 592.374  36.2670849              -24.173918     -20.81695 -30.187547
## 594.636 -30.8588782                7.582107     -12.43298   1.337002
## 694.767  -0.9740867              -14.112900      49.72905 -24.541018
## 808.935 -30.8591166                7.581868     -12.43298   1.336764
##         chandoanshocknhiemtrung:gioinu chandoanxogan:gioinu
## 103.975                      21.938318            -5.999806
## 108.516                      21.938511            -5.999806
## 118.037                      -6.190533           -10.124581
## 119.016                      -6.190533           -10.124581
## 138.995                      -6.190533           -10.124581
## 154.745                      -8.021063            39.111740
## 166.358                      -6.190533           -10.124581
## 180.441                      -8.021063            39.111740
## 182.349                     -19.403167            -4.609902
## 199.119                      -8.021063            39.111740
## 201.211                      -8.021063            39.111740
## 209.545                     -19.359712            -9.332335
## 210.187                     -19.403167            -4.609902
## 223.049                      -8.021063            39.111740
## 223.836                      21.937451            -5.999806
## 229.404                     -19.403167            -4.609902
## 236.528                      21.937476            -5.999806
## 240.058                      21.937664            -5.999806
## 248.788                      -8.021063            39.111740
## 251.811                     -19.403167            -4.609902
## 253.377                      -6.190533           -10.124581
## 256.451                     -19.359712            -9.332335
## 256.623                      -8.021063            39.111740
## 259.216                      21.937463            -5.999806
## 261.591                      -6.750533            -4.809335
## 273.706                      21.937533            -5.999806
## 274.221                     -19.403167            -4.609902
## 277.902                     -19.359712            -9.332335
## 285.098                     -19.359712            -9.332335
## 285.398                      -6.750533            -4.809335
## 287.85                       -6.190533           -10.124581
## 290.612                      -6.190533           -10.124581
## 290.641                      21.937550            -5.999806
## 290.785                      -6.750533            -4.809335
## 291.173                      -8.021063            39.111740
## 291.557                      -8.021063            39.111739
## 294.762                     -19.359712            -9.332335
## 297.156                      -6.750533            -4.809335
## 305.073                      -6.190533           -10.124581
## 305.565                      -6.750533            -4.809335
## 306.556                     -19.359712            -9.332335
## 312.464                      -6.750533            -4.809335
## 312.797                     -19.403167            -4.609902
## 312.808                      21.937486            -5.999806
## 314.154                      -6.190533           -10.124581
## 321.9                        21.938016            -5.999806
## 322.317                      -6.750533            -4.809335
## 327.601                      -8.021063            39.111739
## 328.973                     -19.403167            -4.609902
## 330.333                      -8.021063            39.111740
## 330.903                     -19.359712            -9.332335
## 331.837                      -6.190533           -10.124581
## 332.761                      -6.750533            -4.809335
## 334.469                      -6.190533           -10.124581
## 339.945                      -6.750533            -4.809335
## 340.431                      21.937408            -5.999806
## 347.8                        -6.750533            -4.809335
## 349.491                     -19.359712            -9.332335
## 350.981                      -6.750533            -4.809335
## 356.414                      -8.021063            39.111739
## 357.809                     -19.359712            -9.332335
## 360.229                      -6.750533            -4.809335
## 362.996                      -6.750533            -4.809335
## 366.093                     -19.403167            -4.609902
## 369.956                      21.937394            -5.999806
## 374.278                      -6.750533            -4.809335
## 377.571                     -19.403167            -4.609902
## 378.873                      21.937849            -5.999806
## 381.608                     -19.403167            -4.609902
## 386.756                     -19.359712            -9.332335
## 387.685                     -19.359712            -9.332335
## 388.897                     -19.403167            -4.609902
## 393.754                      21.937848            -5.999806
## 398.638                     -19.403167            -4.609902
## 401.292                      -8.021063            39.111740
## 406.177                     -19.359712            -9.332335
## 413.032                     -19.359712            -9.332335
## 415.402                     -19.359712            -9.332335
## 427.158                     -19.359712            -9.332335
## 458.423                     -19.359712            -9.332335
## 460.808                      -6.750533            -4.809335
## 462.363                      21.936657            -5.999806
## 465.134                     -19.403167            -4.609902
## 476.553                      -6.190533           -10.124581
## 476.743                     -19.403167            -4.609902
## 496.612                      -6.190533           -10.124581
## 563.558                      21.938016            -5.999806
## 590.747                      -8.021063            39.111740
## 592.374                      -6.750533            -4.809335
## 594.636                      21.937677            -5.999806
## 694.767                      -6.190533           -10.124581
## 808.935                      21.937439            -5.999806
## 
## Std. Errors:
##         (Intercept) chandoanshocknhiemtrung chandoanxogan       gioinu
## 103.975   0.3531460            3.531460e-01  3.636027e-07 3.531460e-01
## 108.516   0.3530777            3.530777e-01           NaN 3.530777e-01
## 118.037   0.4818120                     NaN  4.818120e-01          NaN
## 119.016   0.4818121                     NaN  4.818121e-01          NaN
## 138.995   0.4818121            3.186153e-07  4.818121e-01          NaN
## 154.745   0.2409060                     NaN  2.409060e-01 2.409060e-01
## 166.358   0.4818121            1.679264e-07  4.818121e-01 7.843537e-07
## 180.441   0.2409061                     NaN  2.409061e-01 2.409061e-01
## 182.349  81.9128342            8.191283e+01  4.325677e-08 5.963200e+02
## 199.119   0.2409060                     NaN  2.409060e-01 2.409060e-01
## 201.211   0.2409059                     NaN  2.409059e-01 2.409059e-01
## 209.545 127.4306935            9.952473e+02           NaN 1.274307e+02
## 210.187  81.9128342            8.191283e+01           NaN 5.963200e+02
## 223.049   0.2409060                     NaN  2.409060e-01 2.409060e-01
## 223.836   0.3534524            3.534524e-01           NaN 3.534524e-01
## 229.404  81.9128342            8.191283e+01           NaN 5.963200e+02
## 236.528   0.3534435            3.534435e-01           NaN 3.534435e-01
## 240.058   0.3533770            3.533770e-01           NaN 3.533770e-01
## 248.788   0.2409060            1.090026e-08  2.409060e-01 2.409060e-01
## 251.811  81.9128342            8.191283e+01  7.022077e-08 5.963200e+02
## 253.377   0.4818121                     NaN  4.818121e-01          NaN
## 256.451 127.4306935            9.952473e+02  8.306431e-15 1.274307e+02
## 256.623   0.2409060            1.546108e-09  2.409060e-01 2.409060e-01
## 259.216   0.3534482            3.534482e-01  9.671325e-36 3.534482e-01
## 261.591   0.9682566            7.278633e-04  1.408067e-10 4.499183e-03
## 273.706   0.3534233            3.534233e-01  9.747323e-36 3.534233e-01
## 274.221  81.9128342            8.191283e+01  4.209798e-22 5.963200e+02
## 277.902 127.4306935            9.952473e+02  8.316488e-15 1.274307e+02
## 285.098 127.4306935            9.952473e+02  8.316488e-15 1.274307e+02
## 285.398   0.9682566            7.278633e-04  1.403363e-10 4.499183e-03
## 287.85    0.4818121            1.335723e-15  4.818121e-01          NaN
## 290.612   0.4818121            1.297858e-15  4.818121e-01          NaN
## 290.641   0.3534172            3.534172e-01  9.702387e-36 3.534172e-01
## 290.785   0.9682566            7.278633e-04  1.396786e-10 4.499183e-03
## 291.173   0.2409061            3.050634e-09  2.409061e-01 2.409061e-01
## 291.557   0.2409061                     NaN  2.409061e-01 2.409061e-01
## 294.762 127.4306935            9.952473e+02  8.316488e-15 1.274307e+02
## 297.156   0.9682566            7.278633e-04  1.396562e-10 4.499183e-03
## 305.073   0.4818121            1.200739e-15  4.818121e-01          NaN
## 305.565   0.9682566            7.278633e-04  1.407439e-10 4.499183e-03
## 306.556 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 312.464   0.9682566            7.278633e-04  1.409333e-10 4.499183e-03
## 312.797  81.9128342            8.191283e+01  4.209799e-22 5.963200e+02
## 312.808   0.3534400            3.534400e-01  9.823492e-36 3.534400e-01
## 314.154   0.4818121            1.266621e-15  4.818121e-01          NaN
## 321.9     0.3532524            3.532524e-01  9.774661e-36 3.532524e-01
## 322.317   0.9682566            7.278633e-04  1.402801e-10 4.499183e-03
## 327.601   0.2409061                     NaN  2.409061e-01 2.409061e-01
## 328.973  81.9128342            8.191283e+01  4.209799e-22 5.963200e+02
## 330.333   0.2409060            2.140449e-09  2.409060e-01 2.409060e-01
## 330.903 127.4306935            9.952474e+02  8.316488e-15 1.274307e+02
## 331.837   0.4818121            1.276445e-15  4.818121e-01          NaN
## 332.761   0.9682566            7.278633e-04  1.394856e-10 4.499183e-03
## 334.469   0.4818121            1.266440e-15  4.818121e-01          NaN
## 339.945   0.9682566            7.278633e-04  1.405054e-10 4.499183e-03
## 340.431   0.3534677            3.534677e-01  9.673573e-36 3.534677e-01
## 347.8     0.9682566            7.278633e-04  1.400102e-10 4.499183e-03
## 349.491 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 350.981   0.9682566            7.278633e-04  1.399485e-10 4.499183e-03
## 356.414   0.2409061            2.835271e-09  2.409061e-01 2.409061e-01
## 357.809 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 360.229   0.9682566            7.278633e-04  1.393340e-10 4.499183e-03
## 362.996   0.9682566            7.278633e-04  1.410873e-10 4.499183e-03
## 366.093  81.9128342            8.191283e+01  4.209799e-22 5.963200e+02
## 369.956   0.3534725            3.534725e-01  9.735290e-36 3.534725e-01
## 374.278   0.9682566            7.278633e-04  1.421789e-10 4.499183e-03
## 377.571  81.9128342            8.191283e+01  4.209798e-22 5.963200e+02
## 378.873   0.3533114            3.533114e-01  9.809990e-36 3.533114e-01
## 381.608  81.9128342            8.191283e+01  4.209798e-22 5.963200e+02
## 386.756 127.4306935            9.952475e+02  8.316486e-15 1.274307e+02
## 387.685 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 388.897  81.9128342            8.191283e+01  4.209799e-22 5.963200e+02
## 393.754   0.3533120            3.533120e-01  9.654381e-36 3.533120e-01
## 398.638  81.9128342            8.191283e+01  4.209800e-22 5.963200e+02
## 401.292   0.2409060                     NaN  2.409060e-01 2.409060e-01
## 406.177 127.4306935            9.952473e+02  8.316488e-15 1.274307e+02
## 413.032 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 415.402 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 427.158 127.4306935            9.952473e+02  8.316488e-15 1.274307e+02
## 458.423 127.4306935            9.952474e+02  8.316487e-15 1.274307e+02
## 460.808   0.9682566            7.278633e-04  1.413468e-10 4.499183e-03
## 462.363   0.3537337            3.537337e-01  9.718498e-36 3.537337e-01
## 465.134  81.9128342            8.191283e+01  4.209774e-22 5.963200e+02
## 476.553   0.4818120            1.254393e-15  4.818120e-01          NaN
## 476.743  81.9128342            8.191283e+01  4.209798e-22 5.963200e+02
## 496.612   0.4818120            1.326032e-15  4.818120e-01          NaN
## 563.558   0.3532524            3.532524e-01  9.651496e-36 3.532524e-01
## 590.747   0.2409060                     NaN  2.409060e-01 2.409060e-01
## 592.374   0.9682566            7.278633e-04  1.401594e-10 4.499183e-03
## 594.636   0.3533723            3.533723e-01  9.793705e-36 3.533723e-01
## 694.767   0.4818120            1.298093e-15  4.818120e-01          NaN
## 808.935   0.3534566            3.534566e-01  9.647063e-36 3.534566e-01
##         chandoanshocknhiemtrung:gioinu chandoanxogan:gioinu
## 103.975                   3.531460e-01                  NaN
## 108.516                   3.530777e-01         3.802164e-07
## 118.037                            NaN                  NaN
## 119.016                            NaN         3.555750e-07
## 138.995                            NaN         2.417626e-07
## 154.745                   4.384184e-07         2.409060e-01
## 166.358                   1.058981e-06         3.281085e-07
## 180.441                   3.477205e-07         2.409061e-01
## 182.349                   5.963200e+02         5.065877e-07
## 199.119                            NaN         2.409060e-01
## 201.211                   1.519013e-07         2.409059e-01
## 209.545                   9.952473e+02         5.464350e-07
## 210.187                   5.963200e+02         2.791077e-07
## 223.049                            NaN         2.409060e-01
## 223.836                   3.534524e-01                  NaN
## 229.404                   5.963200e+02         1.337618e-07
## 236.528                   3.534435e-01         1.073214e-07
## 240.058                   3.533770e-01                  NaN
## 248.788                            NaN         2.409060e-01
## 251.811                   5.963200e+02         2.795492e-08
## 253.377                            NaN                  NaN
## 256.451                   9.952473e+02         8.316488e-15
## 256.623                   1.546108e-09         2.409060e-01
## 259.216                   3.534482e-01         1.007757e-42
## 261.591                   1.881733e-07                  NaN
## 273.706                   3.534233e-01         1.007496e-42
## 274.221                   5.963200e+02         2.991790e-40
## 277.902                   9.952473e+02         8.316488e-15
## 285.098                   9.952473e+02         8.316488e-15
## 285.398                   1.886031e-07                  NaN
## 287.85                    6.611985e-16                  NaN
## 290.612                   5.919626e-16                  NaN
## 290.641                   3.534172e-01         1.010449e-42
## 290.785                   1.874701e-07                  NaN
## 291.173                   3.050634e-09         2.409061e-01
## 291.557                            NaN         2.409061e-01
## 294.762                   9.952473e+02         8.316488e-15
## 297.156                   1.879866e-07                  NaN
## 305.073                   3.199305e-16                  NaN
## 305.565                   1.888124e-07                  NaN
## 306.556                   9.952474e+02         8.316487e-15
## 312.464                   1.872901e-07                  NaN
## 312.797                   5.963200e+02         2.991951e-40
## 312.808                   3.534400e-01         1.009434e-42
## 314.154                   5.124377e-16                  NaN
## 321.9                     3.532524e-01         1.006465e-42
## 322.317                   1.878346e-07                  NaN
## 327.601                            NaN         2.409061e-01
## 328.973                   5.963200e+02         2.991741e-40
## 330.333                   2.141033e-09         2.409060e-01
## 330.903                   9.952474e+02         8.316488e-15
## 331.837                   5.350971e-16                  NaN
## 332.761                   1.892069e-07                  NaN
## 334.469                   5.153291e-16                  NaN
## 339.945                   1.877003e-07                  NaN
## 340.431                   3.534677e-01         1.010557e-42
## 347.8                     1.886623e-07                  NaN
## 349.491                   9.952474e+02         8.316487e-15
## 350.981                   1.888949e-07                  NaN
## 356.414                   2.835271e-09         2.409061e-01
## 357.809                   9.952474e+02         8.316487e-15
## 360.229                   1.877701e-07                  NaN
## 362.996                   1.881891e-07                  NaN
## 366.093                   5.963200e+02         2.991880e-40
## 369.956                   3.534725e-01         1.008483e-42
## 374.278                   1.886682e-07                  NaN
## 377.571                   5.963200e+02         2.991829e-40
## 378.873                   3.533114e-01         1.010781e-42
## 381.608                   5.963200e+02         2.991866e-40
## 386.756                   9.952475e+02         8.316486e-15
## 387.685                   9.952474e+02         8.316487e-15
## 388.897                   5.963200e+02         2.991866e-40
## 393.754                   3.533120e-01         1.009878e-42
## 398.638                   5.963200e+02         2.991878e-40
## 401.292                            NaN         2.409060e-01
## 406.177                   9.952473e+02         8.316488e-15
## 413.032                   9.952474e+02         8.316487e-15
## 415.402                   9.952474e+02         8.316487e-15
## 427.158                   9.952473e+02         8.316488e-15
## 458.423                   9.952474e+02         8.316487e-15
## 460.808                   1.873184e-07                  NaN
## 462.363                   3.537337e-01         1.008684e-42
## 465.134                   5.963200e+02         2.991950e-40
## 476.553                   4.831781e-16                  NaN
## 476.743                   5.963200e+02         2.992066e-40
## 496.612                   6.407326e-16                  NaN
## 563.558                   3.532524e-01         1.010073e-42
## 590.747                            NaN         2.409060e-01
## 592.374                   1.885252e-07                  NaN
## 594.636                   3.533723e-01         1.009872e-42
## 694.767                   5.926583e-16                  NaN
## 808.935                   3.534566e-01         1.006794e-42
## 
## Residual Deviance: 511.0153 
## AIC: 1615.015

gọi thư viện

library(bayesplot) ;
## This is bayesplot version 1.10.0
## - Online documentation and vignettes at mc-stan.org/bayesplot
## - bayesplot theme set to bayesplot::theme_default()
##    * Does _not_ affect other ggplot2 plots
##    * See ?bayesplot_theme_set for details on theme setting
## 
## Attaching package: 'bayesplot'
## The following object is masked from 'package:brms':
## 
##     rhat
library(ggplot2)
  p = ggplot(dongmau, aes(x = tckDER, chandoan = chandoan))
  p + geom_density(aes(fill = chandoan), alpha=0.5) + theme_light(base_size = 12)

library(rstan)
## Warning: package 'rstan' was built under R version 4.3.2
## Loading required package: StanHeaders
## 
## rstan version 2.32.3 (Stan version 2.26.1)
## For execution on a local, multicore CPU with excess RAM we recommend calling
## options(mc.cores = parallel::detectCores()).
## To avoid recompilation of unchanged Stan programs, we recommend calling
## rstan_options(auto_write = TRUE)
## For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
## change `threads_per_chain` option:
## rstan_options(threads_per_chain = 1)
## Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
## 
## Attaching package: 'rstan'
## The following object is masked from 'package:tidyr':
## 
##     extract
library(shinystan)
## Loading required package: shiny
## Warning: package 'shiny' was built under R version 4.3.2
## 
## This is shinystan version 2.6.0
library(rstanarm)
library(brms)
set.seed(123)

Không Intercept

prior1 = get_prior(tckDER ~ chandoan-1, family = gaussian, data = dongmau, iter = 1000)
 bf.2 = brm(data = dongmau, tckDER ~ chandoan-1,   prior1, family = gaussian, chains = 2, iter = 1000)
## Compiling Stan program...
## Start sampling
## 
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 3.3e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.33 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1: 
## Chain 1: 
## Chain 1: Iteration:   1 / 1000 [  0%]  (Warmup)
## Chain 1: Iteration: 100 / 1000 [ 10%]  (Warmup)
## Chain 1: Iteration: 200 / 1000 [ 20%]  (Warmup)
## Chain 1: Iteration: 300 / 1000 [ 30%]  (Warmup)
## Chain 1: Iteration: 400 / 1000 [ 40%]  (Warmup)
## Chain 1: Iteration: 500 / 1000 [ 50%]  (Warmup)
## Chain 1: Iteration: 501 / 1000 [ 50%]  (Sampling)
## Chain 1: Iteration: 600 / 1000 [ 60%]  (Sampling)
## Chain 1: Iteration: 700 / 1000 [ 70%]  (Sampling)
## Chain 1: Iteration: 800 / 1000 [ 80%]  (Sampling)
## Chain 1: Iteration: 900 / 1000 [ 90%]  (Sampling)
## Chain 1: Iteration: 1000 / 1000 [100%]  (Sampling)
## Chain 1: 
## Chain 1:  Elapsed Time: 0.157 seconds (Warm-up)
## Chain 1:                0.008 seconds (Sampling)
## Chain 1:                0.165 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 7e-06 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.07 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2: 
## Chain 2: 
## Chain 2: Iteration:   1 / 1000 [  0%]  (Warmup)
## Chain 2: Iteration: 100 / 1000 [ 10%]  (Warmup)
## Chain 2: Iteration: 200 / 1000 [ 20%]  (Warmup)
## Chain 2: Iteration: 300 / 1000 [ 30%]  (Warmup)
## Chain 2: Iteration: 400 / 1000 [ 40%]  (Warmup)
## Chain 2: Iteration: 500 / 1000 [ 50%]  (Warmup)
## Chain 2: Iteration: 501 / 1000 [ 50%]  (Sampling)
## Chain 2: Iteration: 600 / 1000 [ 60%]  (Sampling)
## Chain 2: Iteration: 700 / 1000 [ 70%]  (Sampling)
## Chain 2: Iteration: 800 / 1000 [ 80%]  (Sampling)
## Chain 2: Iteration: 900 / 1000 [ 90%]  (Sampling)
## Chain 2: Iteration: 1000 / 1000 [100%]  (Sampling)
## Chain 2: 
## Chain 2:  Elapsed Time: 0.174 seconds (Warm-up)
## Chain 2:                0.01 seconds (Sampling)
## Chain 2:                0.184 seconds (Total)
## Chain 2:
 bf.2$fit
## Inference for Stan model: anon_model.
## 2 chains, each with iter=1000; warmup=500; thin=1; 
## post-warmup draws per chain=500, total post-warmup draws=1000.
## 
##                              mean se_mean    sd    2.5%     25%     50%     75%
## b_chandoanbinhthuong       348.00    0.70 22.81  303.30  333.50  348.09  362.44
## b_chandoanshocknhiemtrung  334.05    0.60 20.83  293.66  319.62  334.33  347.50
## b_chandoanxogan            299.07    0.80 25.55  245.56  282.05  299.00  315.10
## sigma                      123.58    0.33  9.23  106.95  117.04  123.07  129.55
## lprior                      -5.75    0.00  0.11   -5.98   -5.82   -5.74   -5.68
## lp__                      -581.00    0.07  1.55 -585.11 -581.88 -580.60 -579.83
##                             97.5% n_eff Rhat
## b_chandoanbinhthuong       394.41  1071    1
## b_chandoanshocknhiemtrung  376.67  1220    1
## b_chandoanxogan            350.97  1011    1
## sigma                      143.45   792    1
## lprior                      -5.56   796    1
## lp__                      -579.10   461    1
## 
## Samples were drawn using NUTS(diag_e) at Tue Dec 26 20:50:03 2023.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
 pairs(bf.2)

kiem dinh gia thuyet

 hypothesis(bf.2, "chandoanxogan > chandoanbinhthuong", digits = 4)
## Hypothesis Tests for class b:
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (chandoanxogan)-(... > 0   -48.93     33.71   -105.2     8.48       0.08
##   Post.Prob Star
## 1      0.07     
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.
 hypothesis(bf.2, "chandoanshocknhiemtrung > chandoanbinhthuong", digits = 4)
## Hypothesis Tests for class b:
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (chandoanshocknhi... > 0   -13.95     31.02   -65.31    33.92       0.49
##   Post.Prob Star
## 1      0.33     
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.
 hypothesis(bf.2, "chandoanshocknhiemtrung > chandoanxogan", digits = 4)
## Hypothesis Tests for class b:
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (chandoanshocknhi... > 0    34.98     33.26   -21.58    88.68       5.76
##   Post.Prob Star
## 1      0.85     
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.
plot(bf.2, ignore_prior = T, theme = ggplot2::theme())

 marginal_effects(bf.2, probs=c(0.05,0.95), conditions=chandoan)
## Warning: Method 'marginal_effects' is deprecated. Please use
## 'conditional_effects' instead.
## Warning: Argument 'probs' is deprecated. Please use 'prob' instead.
## Warning: The following variables in 'conditions' are not part of the model:
## 'conditions'

Co Intercept tckDER chandoan

 prior1b = get_prior(tckDER ~ chandoan*gioi*tuoi,
                   family = gaussian, data = dongmau)
 bf.2b = brm(data = dongmau, tckDER ~ chandoan*gioi*tuoi,
           prior1b, family = gaussian, chains = 2, iter = 1000)
## Compiling Stan program...
## Start sampling
## 
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 4e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.4 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1: 
## Chain 1: 
## Chain 1: Iteration:   1 / 1000 [  0%]  (Warmup)
## Chain 1: Iteration: 100 / 1000 [ 10%]  (Warmup)
## Chain 1: Iteration: 200 / 1000 [ 20%]  (Warmup)
## Chain 1: Iteration: 300 / 1000 [ 30%]  (Warmup)
## Chain 1: Iteration: 400 / 1000 [ 40%]  (Warmup)
## Chain 1: Iteration: 500 / 1000 [ 50%]  (Warmup)
## Chain 1: Iteration: 501 / 1000 [ 50%]  (Sampling)
## Chain 1: Iteration: 600 / 1000 [ 60%]  (Sampling)
## Chain 1: Iteration: 700 / 1000 [ 70%]  (Sampling)
## Chain 1: Iteration: 800 / 1000 [ 80%]  (Sampling)
## Chain 1: Iteration: 900 / 1000 [ 90%]  (Sampling)
## Chain 1: Iteration: 1000 / 1000 [100%]  (Sampling)
## Chain 1: 
## Chain 1:  Elapsed Time: 0.437 seconds (Warm-up)
## Chain 1:                0.258 seconds (Sampling)
## Chain 1:                0.695 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 1.9e-05 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.19 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2: 
## Chain 2: 
## Chain 2: Iteration:   1 / 1000 [  0%]  (Warmup)
## Chain 2: Iteration: 100 / 1000 [ 10%]  (Warmup)
## Chain 2: Iteration: 200 / 1000 [ 20%]  (Warmup)
## Chain 2: Iteration: 300 / 1000 [ 30%]  (Warmup)
## Chain 2: Iteration: 400 / 1000 [ 40%]  (Warmup)
## Chain 2: Iteration: 500 / 1000 [ 50%]  (Warmup)
## Chain 2: Iteration: 501 / 1000 [ 50%]  (Sampling)
## Chain 2: Iteration: 600 / 1000 [ 60%]  (Sampling)
## Chain 2: Iteration: 700 / 1000 [ 70%]  (Sampling)
## Chain 2: Iteration: 800 / 1000 [ 80%]  (Sampling)
## Chain 2: Iteration: 900 / 1000 [ 90%]  (Sampling)
## Chain 2: Iteration: 1000 / 1000 [100%]  (Sampling)
## Chain 2: 
## Chain 2:  Elapsed Time: 0.499 seconds (Warm-up)
## Chain 2:                0.16 seconds (Sampling)
## Chain 2:                0.659 seconds (Total)
## Chain 2:
  bf.2b$fit
## Inference for Stan model: anon_model.
## 2 chains, each with iter=1000; warmup=500; thin=1; 
## post-warmup draws per chain=500, total post-warmup draws=1000.
## 
##                                          mean se_mean     sd    2.5%     25%
## b_Intercept                            255.67    5.65  99.43   65.76  189.55
## b_chandoanshocknhiemtrung               76.96    9.33 164.81 -258.60  -28.27
## b_chandoanxogan                        -10.09    9.52 180.74 -355.92 -120.47
## b_gioinu                               136.52    7.56 130.12 -115.73   47.35
## b_tuoi                                   2.30    0.14   2.24   -2.19    0.81
## b_chandoanshocknhiemtrung:gioinu        -2.23   15.51 267.76 -494.20 -190.39
## b_chandoanxogan:gioinu                 -46.67   19.62 442.31 -913.83 -326.09
## b_chandoanshocknhiemtrung:tuoi          -2.32    0.19   2.96   -7.99   -4.29
## b_chandoanxogan:tuoi                    -1.15    0.20   3.42   -8.19   -3.35
## b_gioinu:tuoi                           -3.52    0.18   3.08   -9.54   -5.56
## b_chandoanshocknhiemtrung:gioinu:tuoi    1.77    0.29   4.47   -6.90   -1.15
## b_chandoanxogan:gioinu:tuoi              1.71    0.34   6.98  -12.60   -2.79
## sigma                                  129.38    0.41  10.60  111.29  121.79
## lprior                                 -11.40    0.00   0.13  -11.68  -11.48
## lp__                                  -590.39    0.17   3.01 -597.81 -592.13
##                                           50%     75%   97.5% n_eff Rhat
## b_Intercept                            256.64  322.19  451.76   310 1.00
## b_chandoanshocknhiemtrung               80.39  183.68  415.02   312 1.00
## b_chandoanxogan                        -15.77  106.91  358.77   360 1.01
## b_gioinu                               140.47  226.83  373.80   296 1.00
## b_tuoi                                   2.30    3.80    6.67   260 1.01
## b_chandoanshocknhiemtrung:gioinu       -10.13  179.19  529.99   298 1.00
## b_chandoanxogan:gioinu                 -46.74  241.63  820.04   508 1.00
## b_chandoanshocknhiemtrung:tuoi          -2.37   -0.32    4.05   239 1.01
## b_chandoanxogan:tuoi                    -1.01    1.01    5.41   288 1.01
## b_gioinu:tuoi                           -3.57   -1.39    2.60   278 1.00
## b_chandoanshocknhiemtrung:gioinu:tuoi    1.93    4.86    9.68   234 1.00
## b_chandoanxogan:gioinu:tuoi              1.76    6.26   14.98   416 1.00
## sigma                                  128.80  136.28  151.46   685 1.01
## lprior                                 -11.40  -11.31  -11.19   670 1.00
## lp__                                  -589.94 -588.22 -585.69   315 1.00
## 
## Samples were drawn using NUTS(diag_e) at Tue Dec 26 20:51:08 2023.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
  pairs(bf.2b)

  hypothesis(bf.2b, "chandoanxogan > chandoanxogan:gioinu:tuoi", digits = 4)
## Hypothesis Tests for class b:
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (chandoanxogan)-(... > 0    -11.8    177.18  -301.78   292.06       0.82
##   Post.Prob Star
## 1      0.45     
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.
  plot(bf.2, ignore_prior = T, theme = ggplot2::theme())

marginal_effects(bf.2, probs=c(0.05,0.95),conditions=chandoan)
## Warning: Method 'marginal_effects' is deprecated. Please use
## 'conditional_effects' instead.
## Warning: Argument 'probs' is deprecated. Please use 'prob' instead.
## Warning: The following variables in 'conditions' are not part of the model:
## 'conditions'

launch_shinystan(bf.2, rstudio = getOption(“shinystan.rstudio”))

hết