benjaminrich / table1

79 stars 26 forks source link

Individual P-values for grouped variables under a heading. #122

Open TeunAben opened 7 months ago

TeunAben commented 7 months ago

Dear Benjamin, Thank you for the package, the tables are absolutely fantastic. Currently I am trying to make a table in which I have grouped variables under a heading as described in #98 . The render I used is the following: rndr <- function(x, name, ...){ if(name=="disease"){ d<- Albumin[x, c("Myocardialinfarction", "Congestiveheartfailure", "Peripheralvasculardisease", "Cerebrovasculardisease", "Chronicpulmonarydisease", "Diabetes", "Liverdisease", "Renaldisease")] l <-lapply(Albumin, label)[names(d)] names(d)[!sapply(l,is.null)] <-l[!sapply(l,is.null)] c("", sapply(d, render.default)[2,,drop=T]) }else if(name =="treatment"){ f<- Albumin[x,c("Steroids", "IL_blockers", "Remdesivir","LMWH", "Albumin")] k<- lapply(Albumin, label)[names(f)] names(f)[!sapply(k,is.null)] <-k[!sapply(k,is.null)] c("",sapply(f,render.default)[2,,drop=T]) }else if(name=="Score"){ g<-Albumin[x,c("CharlsonScore","Admission_SOFA","ICU_day_1_SOFA","Max_SOFA", "SAPS_Total")] m<-lapply(Albumin,label)[names(g)] names(g)[!sapply(m,is.null)]<- m[!sapply(m,is.null)] c("", sapply(g,render.continuous.default)[3,,drop=T]) }else if(name== "HNAfractions"){ h<- Albumin[x,c("HMA","HNA1","HNA2")] n<-lapply(Albumin,label)[names(h)] names(h)[!sapply(n,is.null)]<-n[!sapply(n,is.null)] c("",sapply(h,render.continuous.default)[2,,drop=T]) }else{ render.default(x,name,...) } }

or in plain text:

rndr <- function(x, name, ...){ if(name=="disease"){ d<- Albumin[x, c("Myocardialinfarction", "Congestiveheartfailure", "Peripheralvasculardisease", "Cerebrovasculardisease", "Chronicpulmonarydisease", "Diabetes", "Liverdisease", "Renaldisease")] l <-lapply(Albumin, label)[names(d)] names(d)[!sapply(l,is.null)] <-l[!sapply(l,is.null)] c("", sapply(d, render.default)[2,,drop=T]) }else if(name =="treatment"){ f<- Albumin[x,c("Steroids", "IL_blockers", "Remdesivir","LMWH", "Albumin")] k<- lapply(Albumin, label)[names(f)] names(f)[!sapply(k,is.null)] <-k[!sapply(k,is.null)] c("",sapply(f,render.default)[2,,drop=T]) }else if(name=="Score"){ g<-Albumin[x,c("CharlsonScore","Admission_SOFA","ICU_day_1_SOFA","Max_SOFA", "SAPS_Total")] m<-lapply(Albumin,label)[names(g)] names(g)[!sapply(m,is.null)]<- m[!sapply(m,is.null)] c("", sapply(g,render.continuous.default)[3,,drop=T]) }else if(name== "HNAfractions"){ h<- Albumin[x,c("HMA","HNA1","HNA2")] n<-lapply(Albumin,label)[names(h)] names(h)[!sapply(n,is.null)]<-n[!sapply(n,is.null)] c("",sapply(h,render.continuous.default)[2,,drop=T]) }else{ render.default(x,name,...) } }

This gave me the result I wanted for grouping like this:

Scherm­afbeelding 2024-03-06 om 10 37 32

However, now I wanted to use statistical tests to see if any significant differences exist between the groups, which probably means I have to reverse the render before it is possible to perform the tests on the groups. Probably this is some really simple coding but I haven't been able to pull it off. I was wondering if you could possibly help me. If not possible or too hard I can of course do the statistics by hand and add them to the table manually. Kind regards Teun