Generate a comprehensive descriptive table with intergroup comparison.
desc.comp(data,variables,by,margin,avg.num,test.num)A comprehensive descriptive table with statistics and P value for intergroup comparisons.
a data.frame containing the variables to be described and a group variable
a numeric variable indicating the columns of variables to be described.
a number indicating the column of the group variable
calculate the proportion for categorical variables by 1 (row) or 2 (column).
"mean", describe continuous variables with mean and standard deviation; "median", describe continuous variables with median and interquantile range; otherwise, normal distribution test will be conducted, for normal distributed variables, "mean" will be used, otherwise, "median" will be used.
"metric", t test or anova will be used for intergroup comparison; "nonmetric", Wilcoxon rank sum test or Kruskal-Wallis test will be used; otherwise, normal distribution test will be conducted, for normal distributed variables, "metric" will be used, otherwise, "nonmetric" will be used.
Not limited to hospital data, but also applicable to other surveillance data.
desc.comp(CO2,variables=2:5,by=1,margin=1)
Run the code above in your browser using DataLab