1 tableone

1.1 基线特征表

1.2 案例1

Code
data <- read_rds("data/三线表/tableone骨科术式.rds") 


data <- data|> mutate(
    preoperative_pfirmann_level=factor(preoperative_pfirmann_level,
                                       levels=c("Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ"),labels=c("Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ"),ordered = T),
    preoperative_pfirmann_cranial=factor(preoperative_pfirmann_cranial,levels=c(1,2,3,4,5),labels=c(1,2,3,4,5),ordered = T),
    preoperative_pfirmann_caudal=factor(preoperative_pfirmann_caudal,levels=c(1,2,3,4,5),labels=c(1,2,3,4,5),ordered = T),
    postoperative_pfirmann_cranial=factor(postoperative_pfirmann_cranial,levels=c(1,2,3,4,5),labels=c(1,2,3,4,5),ordered = T),
    postoperative_pfirmann_caudal=factor( postoperative_pfirmann_caudal,levels=c(1,2,3,4,5),labels=c(1,2,3,4,5),ordered = T),
)

head(data)
#> # A tibble: 6 × 26
#>   level_of_index_surgery sex     age   bmi preoperative_pfirmann_level
#>   <chr>                  <chr> <dbl> <dbl> <ord>                      
#> 1 L4-5                   F        65  25.2 Ⅲ                          
#> 2 L4-5                   M        72  21.7 Ⅲ                          
#> 3 L3-4                   F        48  23.4 Ⅲ                          
#> 4 L4-5                   F        72  23.4 Ⅳ                          
#> 5 L3-4                   M        60  25.3 Ⅲ                          
#> 6 L4-5                   M        59  24.5 Ⅳ                          
#> # ℹ 21 more variables: preoperative_pfirmann_cranial <ord>,
#> #   preoperative_pfirmann_caudal <ord>, postoperative_pfirmann_cranial <ord>,
#> #   postoperative_pfirmann_caudal <ord>, preoperative_segmented_lordosis <dbl>,
#> #   postoperative_segmented_lordosis <dbl>,
#> #   preoperative_segmented_lordosis_cranial <dbl>,
#> #   postoperative_segmented_lordosis_cranial <dbl>, delta_H <dbl>,
#> #   preoperative_ll <dbl>, postoperative_ll <dbl>, s_asd <fct>, months <dbl>, …
Code
library(tableone)

interest <- names(data)[c(2,3,4,5,14,23,24,26)]
interest
#> [1] "sex"                         "age"                        
#> [3] "bmi"                         "preoperative_pfirmann_level"
#> [5] "delta_H"                     "r_asd"                      
#> [7] "delta_SL"                    "delta_LL"
categories <- interest[c(1,4,6)]

tbl1 <- CreateTableOne(vars = names(data)[-c(1,17:19,21:26)],
               data = data,strata = "group",
               addOverall = T,includeNA = TRUE,
               ) 

print(tbl1, showAllLevels = T,
          nonnormal = c(   # 非正态分布
        "bmi",
        "preoperative_segmented_lordosis",
        "postoperative_segmented_lordosis",
        "preoperative_ll" ,
        "postoperative_ll",
        "postoperative_segmented_lordosis_cranial",
        "delta_H"
    ),
    exact = c(        # fisher 精确检验

        "preoperative_pfirmann_level",
        "preoperative_pfirmann_cranial",
        "preoperative_pfirmann_caudal",
        "postoperative_pfirmann_cranial",
        "postoperative_pfirmann_caudal"
    ))
#>                                                          Stratified by group
#>                                                           level   
#>   n                                                               
#>   sex (%)                                                 F       
#>                                                           M       
#>   age (mean (SD))                                                 
#>   bmi (median [IQR])                                              
#>   preoperative_pfirmann_level (%)                         Ⅰ       
#>                                                           Ⅱ       
#>                                                           Ⅲ       
#>                                                           Ⅳ       
#>                                                           Ⅴ       
#>   preoperative_pfirmann_cranial (%)                       1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   preoperative_pfirmann_caudal (%)                        1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   postoperative_pfirmann_cranial (%)                      1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   postoperative_pfirmann_caudal (%)                       1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   preoperative_segmented_lordosis (median [IQR])                  
#>   postoperative_segmented_lordosis (median [IQR])                 
#>   preoperative_segmented_lordosis_cranial (mean (SD))             
#>   postoperative_segmented_lordosis_cranial (median [IQR])         
#>   delta_H (median [IQR])                                          
#>   preoperative_ll (median [IQR])                                  
#>   postoperative_ll (median [IQR])                                 
#>   group (%)                                               TLIF    
#>                                                           Mis-LLIF
#>                                                          Stratified by group
#>                                                           Overall             
#>   n                                                         140               
#>   sex (%)                                                    64 (45.7)        
#>                                                              76 (54.3)        
#>   age (mean (SD))                                         62.72 (5.90)        
#>   bmi (median [IQR])                                      25.20 [24.28, 26.10]
#>   preoperative_pfirmann_level (%)                             0 ( 0.0)        
#>                                                               0 ( 0.0)        
#>                                                             103 (73.6)        
#>                                                              34 (24.3)        
#>                                                               3 ( 2.1)        
#>   preoperative_pfirmann_cranial (%)                           0 ( 0.0)        
#>                                                               1 ( 0.7)        
#>                                                             129 (92.1)        
#>                                                              10 ( 7.1)        
#>                                                               0 ( 0.0)        
#>   preoperative_pfirmann_caudal (%)                            0 ( 0.0)        
#>                                                               1 ( 0.7)        
#>                                                             114 (81.4)        
#>                                                              25 (17.9)        
#>                                                               0 ( 0.0)        
#>   postoperative_pfirmann_cranial (%)                          0 ( 0.0)        
#>                                                               0 ( 0.0)        
#>                                                              94 (67.1)        
#>                                                              39 (27.9)        
#>                                                               7 ( 5.0)        
#>   postoperative_pfirmann_caudal (%)                           0 ( 0.0)        
#>                                                               0 ( 0.0)        
#>                                                             103 (73.6)        
#>                                                              33 (23.6)        
#>                                                               4 ( 2.9)        
#>   preoperative_segmented_lordosis (median [IQR])           6.50 [5.30, 8.60]  
#>   postoperative_segmented_lordosis (median [IQR])          8.50 [8.07, 9.72]  
#>   preoperative_segmented_lordosis_cranial (mean (SD))      7.60 (1.33)        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  7.95 [6.90, 8.90]  
#>   delta_H (median [IQR])                                   1.75 [0.90, 3.90]  
#>   preoperative_ll (median [IQR])                          46.80 [43.75, 48.60]
#>   postoperative_ll (median [IQR])                         47.80 [46.18, 49.60]
#>   group (%)                                                  70 (50.0)        
#>                                                              70 (50.0)        
#>                                                          Stratified by group
#>                                                           TLIF                
#>   n                                                          70               
#>   sex (%)                                                    30 ( 42.9)       
#>                                                              40 ( 57.1)       
#>   age (mean (SD))                                         62.89 (5.37)        
#>   bmi (median [IQR])                                      25.25 [24.35, 26.08]
#>   preoperative_pfirmann_level (%)                             0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              52 ( 74.3)       
#>                                                              18 ( 25.7)       
#>                                                               0 (  0.0)       
#>   preoperative_pfirmann_cranial (%)                           0 (  0.0)       
#>                                                               1 (  1.4)       
#>                                                              65 ( 92.9)       
#>                                                               4 (  5.7)       
#>                                                               0 (  0.0)       
#>   preoperative_pfirmann_caudal (%)                            0 (  0.0)       
#>                                                               1 (  1.4)       
#>                                                              56 ( 80.0)       
#>                                                              13 ( 18.6)       
#>                                                               0 (  0.0)       
#>   postoperative_pfirmann_cranial (%)                          0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              49 ( 70.0)       
#>                                                              21 ( 30.0)       
#>                                                               0 (  0.0)       
#>   postoperative_pfirmann_caudal (%)                           0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              52 ( 74.3)       
#>                                                              18 ( 25.7)       
#>                                                               0 (  0.0)       
#>   preoperative_segmented_lordosis (median [IQR])           7.55 [5.90, 8.60]  
#>   postoperative_segmented_lordosis (median [IQR])          8.40 [7.73, 9.45]  
#>   preoperative_segmented_lordosis_cranial (mean (SD))      7.62 (1.22)        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  7.95 [6.90, 8.78]  
#>   delta_H (median [IQR])                                   0.90 [0.72, 1.17]  
#>   preoperative_ll (median [IQR])                          46.90 [45.37, 48.90]
#>   postoperative_ll (median [IQR])                         47.85 [46.50, 49.60]
#>   group (%)                                                  70 (100.0)       
#>                                                               0 (  0.0)       
#>                                                          Stratified by group
#>                                                           Mis-LLIF            
#>   n                                                          70               
#>   sex (%)                                                    34 ( 48.6)       
#>                                                              36 ( 51.4)       
#>   age (mean (SD))                                         62.56 (6.43)        
#>   bmi (median [IQR])                                      25.20 [24.10, 26.05]
#>   preoperative_pfirmann_level (%)                             0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              51 ( 72.9)       
#>                                                              16 ( 22.9)       
#>                                                               3 (  4.3)       
#>   preoperative_pfirmann_cranial (%)                           0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              64 ( 91.4)       
#>                                                               6 (  8.6)       
#>                                                               0 (  0.0)       
#>   preoperative_pfirmann_caudal (%)                            0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              58 ( 82.9)       
#>                                                              12 ( 17.1)       
#>                                                               0 (  0.0)       
#>   postoperative_pfirmann_cranial (%)                          0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              45 ( 64.3)       
#>                                                              18 ( 25.7)       
#>                                                               7 ( 10.0)       
#>   postoperative_pfirmann_caudal (%)                           0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              51 ( 72.9)       
#>                                                              15 ( 21.4)       
#>                                                               4 (  5.7)       
#>   preoperative_segmented_lordosis (median [IQR])           5.60 [5.30, 8.12]  
#>   postoperative_segmented_lordosis (median [IQR])          8.60 [8.30, 10.30] 
#>   preoperative_segmented_lordosis_cranial (mean (SD))      7.58 (1.44)        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  7.95 [6.93, 9.00]  
#>   delta_H (median [IQR])                                   3.90 [3.52, 4.60]  
#>   preoperative_ll (median [IQR])                          46.25 [43.23, 48.30]
#>   postoperative_ll (median [IQR])                         47.65 [45.23, 49.45]
#>   group (%)                                                   0 (  0.0)       
#>                                                              70 (100.0)       
#>                                                          Stratified by group
#>                                                           p      test   
#>   n                                                                     
#>   sex (%)                                                  0.611        
#>                                                                         
#>   age (mean (SD))                                          0.743        
#>   bmi (median [IQR])                                       0.425 nonnorm
#>   preoperative_pfirmann_level (%)                          0.295 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   preoperative_pfirmann_cranial (%)                        0.745 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   preoperative_pfirmann_caudal (%)                         0.828 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   postoperative_pfirmann_cranial (%)                       0.025 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   postoperative_pfirmann_caudal (%)                        0.136 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   preoperative_segmented_lordosis (median [IQR])           0.010 nonnorm
#>   postoperative_segmented_lordosis (median [IQR])          0.009 nonnorm
#>   preoperative_segmented_lordosis_cranial (mean (SD))      0.854        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  0.350 nonnorm
#>   delta_H (median [IQR])                                  <0.001 nonnorm
#>   preoperative_ll (median [IQR])                           0.095 nonnorm
#>   postoperative_ll (median [IQR])                          0.769 nonnorm
#>   group (%)                                               <0.001        
#> 

tbl1 %>% print(
    nonnormal = c(   # 非正态分布
        "bmi",
        "preoperative_segmented_lordosis",
        "postoperative_segmented_lordosis",
        "preoperative_ll" ,
        "postoperative_ll",
        "postoperative_segmented_lordosis_cranial",
        "delta_H"
    ),
    exact = c(        # fisher 精确检验

        "preoperative_pfirmann_level",
        "preoperative_pfirmann_cranial",
        "preoperative_pfirmann_caudal",
        "postoperative_pfirmann_cranial",
        "postoperative_pfirmann_caudal"
    ),
    showAllLevels = T,
    smd = F,
    formatOptions = list(big.mark = ",")
) %>%
    write.csv("data/三线表/tableone生成三线表.csv")
#>                                                          Stratified by group
#>                                                           level   
#>   n                                                               
#>   sex (%)                                                 F       
#>                                                           M       
#>   age (mean (SD))                                                 
#>   bmi (median [IQR])                                              
#>   preoperative_pfirmann_level (%)                         Ⅰ       
#>                                                           Ⅱ       
#>                                                           Ⅲ       
#>                                                           Ⅳ       
#>                                                           Ⅴ       
#>   preoperative_pfirmann_cranial (%)                       1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   preoperative_pfirmann_caudal (%)                        1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   postoperative_pfirmann_cranial (%)                      1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   postoperative_pfirmann_caudal (%)                       1       
#>                                                           2       
#>                                                           3       
#>                                                           4       
#>                                                           5       
#>   preoperative_segmented_lordosis (median [IQR])                  
#>   postoperative_segmented_lordosis (median [IQR])                 
#>   preoperative_segmented_lordosis_cranial (mean (SD))             
#>   postoperative_segmented_lordosis_cranial (median [IQR])         
#>   delta_H (median [IQR])                                          
#>   preoperative_ll (median [IQR])                                  
#>   postoperative_ll (median [IQR])                                 
#>   group (%)                                               TLIF    
#>                                                           Mis-LLIF
#>                                                          Stratified by group
#>                                                           Overall             
#>   n                                                         140               
#>   sex (%)                                                    64 (45.7)        
#>                                                              76 (54.3)        
#>   age (mean (SD))                                         62.72 (5.90)        
#>   bmi (median [IQR])                                      25.20 [24.28, 26.10]
#>   preoperative_pfirmann_level (%)                             0 ( 0.0)        
#>                                                               0 ( 0.0)        
#>                                                             103 (73.6)        
#>                                                              34 (24.3)        
#>                                                               3 ( 2.1)        
#>   preoperative_pfirmann_cranial (%)                           0 ( 0.0)        
#>                                                               1 ( 0.7)        
#>                                                             129 (92.1)        
#>                                                              10 ( 7.1)        
#>                                                               0 ( 0.0)        
#>   preoperative_pfirmann_caudal (%)                            0 ( 0.0)        
#>                                                               1 ( 0.7)        
#>                                                             114 (81.4)        
#>                                                              25 (17.9)        
#>                                                               0 ( 0.0)        
#>   postoperative_pfirmann_cranial (%)                          0 ( 0.0)        
#>                                                               0 ( 0.0)        
#>                                                              94 (67.1)        
#>                                                              39 (27.9)        
#>                                                               7 ( 5.0)        
#>   postoperative_pfirmann_caudal (%)                           0 ( 0.0)        
#>                                                               0 ( 0.0)        
#>                                                             103 (73.6)        
#>                                                              33 (23.6)        
#>                                                               4 ( 2.9)        
#>   preoperative_segmented_lordosis (median [IQR])           6.50 [5.30, 8.60]  
#>   postoperative_segmented_lordosis (median [IQR])          8.50 [8.07, 9.72]  
#>   preoperative_segmented_lordosis_cranial (mean (SD))      7.60 (1.33)        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  7.95 [6.90, 8.90]  
#>   delta_H (median [IQR])                                   1.75 [0.90, 3.90]  
#>   preoperative_ll (median [IQR])                          46.80 [43.75, 48.60]
#>   postoperative_ll (median [IQR])                         47.80 [46.18, 49.60]
#>   group (%)                                                  70 (50.0)        
#>                                                              70 (50.0)        
#>                                                          Stratified by group
#>                                                           TLIF                
#>   n                                                          70               
#>   sex (%)                                                    30 ( 42.9)       
#>                                                              40 ( 57.1)       
#>   age (mean (SD))                                         62.89 (5.37)        
#>   bmi (median [IQR])                                      25.25 [24.35, 26.08]
#>   preoperative_pfirmann_level (%)                             0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              52 ( 74.3)       
#>                                                              18 ( 25.7)       
#>                                                               0 (  0.0)       
#>   preoperative_pfirmann_cranial (%)                           0 (  0.0)       
#>                                                               1 (  1.4)       
#>                                                              65 ( 92.9)       
#>                                                               4 (  5.7)       
#>                                                               0 (  0.0)       
#>   preoperative_pfirmann_caudal (%)                            0 (  0.0)       
#>                                                               1 (  1.4)       
#>                                                              56 ( 80.0)       
#>                                                              13 ( 18.6)       
#>                                                               0 (  0.0)       
#>   postoperative_pfirmann_cranial (%)                          0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              49 ( 70.0)       
#>                                                              21 ( 30.0)       
#>                                                               0 (  0.0)       
#>   postoperative_pfirmann_caudal (%)                           0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              52 ( 74.3)       
#>                                                              18 ( 25.7)       
#>                                                               0 (  0.0)       
#>   preoperative_segmented_lordosis (median [IQR])           7.55 [5.90, 8.60]  
#>   postoperative_segmented_lordosis (median [IQR])          8.40 [7.73, 9.45]  
#>   preoperative_segmented_lordosis_cranial (mean (SD))      7.62 (1.22)        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  7.95 [6.90, 8.78]  
#>   delta_H (median [IQR])                                   0.90 [0.72, 1.17]  
#>   preoperative_ll (median [IQR])                          46.90 [45.37, 48.90]
#>   postoperative_ll (median [IQR])                         47.85 [46.50, 49.60]
#>   group (%)                                                  70 (100.0)       
#>                                                               0 (  0.0)       
#>                                                          Stratified by group
#>                                                           Mis-LLIF            
#>   n                                                          70               
#>   sex (%)                                                    34 ( 48.6)       
#>                                                              36 ( 51.4)       
#>   age (mean (SD))                                         62.56 (6.43)        
#>   bmi (median [IQR])                                      25.20 [24.10, 26.05]
#>   preoperative_pfirmann_level (%)                             0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              51 ( 72.9)       
#>                                                              16 ( 22.9)       
#>                                                               3 (  4.3)       
#>   preoperative_pfirmann_cranial (%)                           0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              64 ( 91.4)       
#>                                                               6 (  8.6)       
#>                                                               0 (  0.0)       
#>   preoperative_pfirmann_caudal (%)                            0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              58 ( 82.9)       
#>                                                              12 ( 17.1)       
#>                                                               0 (  0.0)       
#>   postoperative_pfirmann_cranial (%)                          0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              45 ( 64.3)       
#>                                                              18 ( 25.7)       
#>                                                               7 ( 10.0)       
#>   postoperative_pfirmann_caudal (%)                           0 (  0.0)       
#>                                                               0 (  0.0)       
#>                                                              51 ( 72.9)       
#>                                                              15 ( 21.4)       
#>                                                               4 (  5.7)       
#>   preoperative_segmented_lordosis (median [IQR])           5.60 [5.30, 8.12]  
#>   postoperative_segmented_lordosis (median [IQR])          8.60 [8.30, 10.30] 
#>   preoperative_segmented_lordosis_cranial (mean (SD))      7.58 (1.44)        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  7.95 [6.93, 9.00]  
#>   delta_H (median [IQR])                                   3.90 [3.52, 4.60]  
#>   preoperative_ll (median [IQR])                          46.25 [43.23, 48.30]
#>   postoperative_ll (median [IQR])                         47.65 [45.23, 49.45]
#>   group (%)                                                   0 (  0.0)       
#>                                                              70 (100.0)       
#>                                                          Stratified by group
#>                                                           p      test   
#>   n                                                                     
#>   sex (%)                                                  0.611        
#>                                                                         
#>   age (mean (SD))                                          0.743        
#>   bmi (median [IQR])                                       0.425 nonnorm
#>   preoperative_pfirmann_level (%)                          0.295 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   preoperative_pfirmann_cranial (%)                        0.745 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   preoperative_pfirmann_caudal (%)                         0.828 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   postoperative_pfirmann_cranial (%)                       0.025 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   postoperative_pfirmann_caudal (%)                        0.136 exact  
#>                                                                         
#>                                                                         
#>                                                                         
#>                                                                         
#>   preoperative_segmented_lordosis (median [IQR])           0.010 nonnorm
#>   postoperative_segmented_lordosis (median [IQR])          0.009 nonnorm
#>   preoperative_segmented_lordosis_cranial (mean (SD))      0.854        
#>   postoperative_segmented_lordosis_cranial (median [IQR])  0.350 nonnorm
#>   delta_H (median [IQR])                                  <0.001 nonnorm
#>   preoperative_ll (median [IQR])                           0.095 nonnorm
#>   postoperative_ll (median [IQR])                          0.769 nonnorm
#>   group (%)                                               <0.001        
#> 

1.2.1 统计检验默认方法

连续变量应用Welch 两样本t检验

Code
t.test(age~group, data = data,var.equal=F)
#> 
#>  Welch Two Sample t-test
#> 
#> data:  age by group
#> t = 0.32815, df = 133.82, p-value = 0.7433
#> alternative hypothesis: true difference in means between group TLIF and group Mis-LLIF is not equal to 0
#> 95 percent confidence interval:
#>  -1.651807  2.308950
#> sample estimates:
#>     mean in group TLIF mean in group Mis-LLIF 
#>               62.88571               62.55714

分类变量应用 Yate校正 的Pearson卡方检验

Code
table(data$sex, data$group) %>% chisq.test(correct = T)
#> 
#>  Pearson's Chi-squared test with Yates' continuity correction
#> 
#> data:  .
#> X-squared = 0.25905, df = 1, p-value = 0.6108
table(data$sex, data$group) %>% chisq.test(correct = F)
#> 
#>  Pearson's Chi-squared test
#> 
#> data:  .
#> X-squared = 0.46053, df = 1, p-value = 0.4974

可能无法校正

Code
table(data$preoperative_pfirmann_level,data$group)[3:5,] %>% chisq.test()
#> Warning in chisq.test(.): Chi-squared approximation may be incorrect
#> 
#>  Pearson's Chi-squared test
#> 
#> data:  .
#> X-squared = 3.1274, df = 2, p-value = 0.2094

table(data$preoperative_pfirmann_level,data$group)[3:5,] %>% fisher.test()
#> 
#>  Fisher's Exact Test for Count Data
#> 
#> data:  .
#> p-value = 0.295
#> alternative hypothesis: two.sided

1.2.2 指定非正态分布

1.2.3 指定精确检验

1.3

Code
library(tableone)

# 创建数据
data <- data.frame(
  group = c(rep("A", 50), rep("B", 50)),
  sex = sample(c("Male", "Female"), 100, replace = TRUE),
  age = rnorm(100, 50, 10),
  bmi = rnorm(100, 25, 4)
)

# 生成表格
tab <- CreateTableOne(vars = c("age", "sex", "bmi"), 
                      strata = "group", 
                      data = data, 
                      test = TRUE)

# 打印表格,包含卡方统计量和t值
print(tab, showAllLevels = TRUE, smd = TRUE)
#>                  Stratified by group
#>                   level  A             B             p      test SMD   
#>   n                         50            50                           
#>   age (mean (SD))        49.68 (10.83) 50.32 (9.41)   0.753       0.063
#>   sex (%)         Female    26 (52.0)     18 (36.0)   0.158       0.327
#>                   Male      24 (48.0)     32 (64.0)                    
#>   bmi (mean (SD))        24.29 (3.07)  24.54 (3.94)   0.716       0.073

Back to top