|
|
@@ -13,6 +13,7 @@ |
|
|
|
#' @param titre Titre du tableau, par defaut "Comparaison selon nom_de_la_variable" |
|
|
|
#' @param variables Vecteur de noms de variables a comparer, par defaut toutes les variables contenues dans la table moins celle servant de comparateur |
|
|
|
#' @param variables_neg Vecteur de noms de variables a exclure de la comparaison |
|
|
|
#' #' @param stats Vecteur de valeurs a calculer, parmi N, \%, \%/moy, moy, \%/med, med, et, ic95, Q1, med, Q3, min et max. Par defaut c("N","\%/moy","et") |
|
|
|
#' @param note Note de bas de page, par defaut vide |
|
|
|
#' @param nbdec Nombre de decimales apres la virgule, par defaut 1 |
|
|
|
#' @param pourcent Pourcentages pour les variables qualitatives, en colonnes ("col") ou en lignes ("row"), par defaut sur le total |
|
|
@@ -26,7 +27,7 @@ |
|
|
|
#' desc_groupe(Ma_table, "sexe", param = para, titre="Comparatif selon le sexe", pourcent="row") |
|
|
|
#' } |
|
|
|
#' @export |
|
|
|
desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NULL, variables=NULL, variables_neg=NULL, note=NULL, nbdec=1, pourcent="total") |
|
|
|
desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NULL, variables=NULL, variables_neg=NULL,stats=c("N","%/moy","et"), note=NULL, nbdec=1, pourcent="total") |
|
|
|
{ |
|
|
|
if (nbdec<2) |
|
|
|
nbdecp<-2 |
|
|
@@ -92,16 +93,15 @@ desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NU |
|
|
|
HTML("<thead>") |
|
|
|
inc() |
|
|
|
|
|
|
|
HTML("<tr><th></th>", paste0("<th colspan='3'>",levels(modulo),"</th>", collapse=""), "<th>p</th></tr>") |
|
|
|
HTML("<tr><th></th>", paste0("<th colspan='",length(stats),"'>",levels(modulo),"</th>", collapse=""), "<th>p</th></tr>") |
|
|
|
|
|
|
|
HTML("<tr><td></td>", sep="") |
|
|
|
for (i in levels(modulo)) |
|
|
|
{ |
|
|
|
HTML("<td colspan='3'>N=", length(na.omit(modulo[modulo==i])), "</td>", sep="") |
|
|
|
} |
|
|
|
HTML("<td colspan='",length(stats),"'>N=", length(na.omit(modulo[modulo==i])), "</td>", sep="") |
|
|
|
|
|
|
|
HTML("<td></td></tr>") |
|
|
|
|
|
|
|
HTML("<tr><td></td>", paste0(rep(c("<td>N</td>","<td>%/moy</td>","<td>et</td>"),nlevels(modulo)),collapse=""), "<td></td></tr>") |
|
|
|
HTML("<tr><td></td>", paste0(rep(paste("<td>",stats,"</td>",sep="", collapse=""),nlevels(modulo)),collapse=""), "<td></td></tr>") |
|
|
|
|
|
|
|
dec() |
|
|
|
HTML("</thead>") |
|
|
@@ -111,7 +111,7 @@ desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NU |
|
|
|
{ |
|
|
|
HTML("<tfoot>") |
|
|
|
inc() |
|
|
|
HTML("<tr><td colspan='", nlevels(modulo)*3+2, "'>", note,"</td></tr>") |
|
|
|
HTML("<tr><td colspan='", nlevels(modulo)*length(stats)+2, "'>", note,"</td></tr>") |
|
|
|
dec() |
|
|
|
HTML("</tfoot>") |
|
|
|
} |
|
|
@@ -158,7 +158,32 @@ desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NU |
|
|
|
HTML("<tr><td class='var'>", etiq, "</td>", sep="") |
|
|
|
|
|
|
|
for (level in levels(modulo)) |
|
|
|
HTML("<td>",length(na.omit(table[[var]][modulo==level])) ,"</td><td>",format(mean(table[[var]][modulo==level], na.rm=T), digits=nbdec,nsmall=nbdec), "</td><td>", format(sd(table[[var]][modulo==level],na.rm=T), digits=nbdec,nsmall=nbdec), "</td>", sep="") |
|
|
|
{ |
|
|
|
for (stat in stats) |
|
|
|
{ |
|
|
|
HTML("<td>",sep="") |
|
|
|
|
|
|
|
HTML(tryCatch( |
|
|
|
{ |
|
|
|
format(switch(stat, |
|
|
|
N = length(na.omit(table[[var]][modulo==level])), |
|
|
|
"%/moy" = , |
|
|
|
moy = mean(table[[var]][modulo==level],na.rm=T), |
|
|
|
"%/med" = , |
|
|
|
med = median(table[[var]][modulo==level],na.rm=T), |
|
|
|
Q1 = quantile(table[[var]][modulo==level], probs=.25, na.rm=T,names=F,type=3), |
|
|
|
Q3 = quantile(table[[var]][modulo==level], probs=.75, na.rm=T,names=F,type=3), |
|
|
|
min = min(table[[var]][modulo==level],na.rm=T), |
|
|
|
max = max(table[[var]][modulo==level],na.rm=T), |
|
|
|
et = sd(table[[var]][modulo==level],na.rm=T), |
|
|
|
ic95 = paste0("±",format(mean(table[[var]][modulo==level],na.rm=T) - t.test(table[[var]][modulo==level])$conf.int[1], digits=nbdec,nsmall=nbdec)), |
|
|
|
... = "ERR" |
|
|
|
),digits=nbdec,nsmall=nbdec) |
|
|
|
},error = function(e){erreur(e,var,"dans le calcul de ",stat)}), sep="") |
|
|
|
|
|
|
|
HTML("</td>", sep="") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HTML("<td>", format(p,digits=nbdecp,nsmall=nbdecp), sep="") |
|
|
|
if (!is.na(p)) |
|
|
@@ -194,7 +219,7 @@ desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NU |
|
|
|
"NA" |
|
|
|
}) |
|
|
|
|
|
|
|
HTML("<tr><td class='var' colspan='", nlevels(modulo)*3+1, "'>", etiq, "</td>", sep="") |
|
|
|
HTML("<tr><td class='var' colspan='", nlevels(modulo)*length(stats)+1, "'>", etiq, "</td>", sep="") |
|
|
|
HTML("<td>", format(p,digits=nbdecp,nsmall=nbdecp), sep="") |
|
|
|
if (!is.na(p)) |
|
|
|
if (p<.05) |
|
|
@@ -208,12 +233,20 @@ desc_groupe <- function(table, groupe, param = character(0), html=NULL, titre=NU |
|
|
|
HTML("<tr><td class='level'>", level, "</td>",sep="") |
|
|
|
for (level_m in levels(modulo)) |
|
|
|
{ |
|
|
|
HTML("<td>", table(table[[var]],modulo)[level,level_m], "</td>", sep="") |
|
|
|
switch(pourcent, |
|
|
|
row = HTML("<td>", format(100*table(table[[var]],modulo)[level,level_m]/rowSums(table(table[[var]],modulo))[level], digits=nbdec, nsmall=nbdec), "</td>", sep=""), |
|
|
|
col = HTML("<td>", format(100*table(table[[var]],modulo)[level,level_m]/colSums(table(table[[var]],modulo))[level_m], digits=nbdec, nsmall=nbdec), "</td>", sep=""), |
|
|
|
total = HTML("<td>", format(100*table(table[[var]],modulo)[level,level_m]/sum(table(table[[var]],modulo)), digits=nbdec, nsmall=nbdec), "</td>", sep="")) |
|
|
|
HTML("<td></td>",sep="") |
|
|
|
for (stat in stats) |
|
|
|
{ |
|
|
|
HTML("<td>",sep="") |
|
|
|
|
|
|
|
if (stat == "N") |
|
|
|
HTML(table(table[[var]],modulo)[level,level_m],sep="") |
|
|
|
else if ((stat == "%") | (stat == "%/moy") | (stat == "%/med")) |
|
|
|
switch(pourcent, |
|
|
|
row = HTML(format(100*table(table[[var]],modulo)[level,level_m]/rowSums(table(table[[var]],modulo))[level], digits=nbdec, nsmall=nbdec), sep=""), |
|
|
|
col = HTML(format(100*table(table[[var]],modulo)[level,level_m]/colSums(table(table[[var]],modulo))[level_m], digits=nbdec, nsmall=nbdec), sep=""), |
|
|
|
total = HTML(format(100*table(table[[var]],modulo)[level,level_m]/sum(table(table[[var]],modulo)), digits=nbdec, nsmall=nbdec), sep="")) |
|
|
|
|
|
|
|
HTML("</td>",sep="") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HTML("<td></td></tr>") |
|
|
|