descrTable {rrMisc} | R Documentation |
Create descriptive table with up to five subgroups/total and comparison between groups.
descrTable(def.measures, sub.d1, sub.d2 = NULL, sub.d3 = NULL, sub.d4 = NULL, sub.d5 = NULL, weights.1 = NULL, weights.2 = NULL, weights.3 = NULL, weights.4 = NULL, weights.5 = NULL, label.compact = FALSE, label.width = 48, test.gr = NULL, lang = "de", group.size.total = 0, big.mark = "'", only.first.label = FALSE, verbose = 0)
def.measures |
description scheme with measures, e.g. from createDefMeasures() |
sub.d1 |
vectors of data in column 1 |
sub.d2 |
vectors of data in column 2 |
sub.d3 |
vectors of data in column 3 |
sub.d4 |
vectors of data in column 4 |
sub.d5 |
vectors of data in column 5 |
weights.1 |
vectors of weights of data column 1 |
weights.2 |
vectors of weights of data column 2 |
weights.3 |
vectors of weights of data column 3 |
weights.4 |
vectors of weights of data column 4 |
weights.5 |
vectors of weights of data column 5 |
label.compact |
If to compact result columns label and measure or make two columns. |
label.width |
Width of first column if label.compact==TRUE. |
test.gr |
Index of columns to compare. |
lang |
Language for certain key words german 'de' or english 'en'. |
group.size.total |
Column for group size total (if 'portion' is requested). |
big.mark |
Thousand separator as used in format(). |
only.first.label |
For multiple lines of a label, show label only in first line |
verbose |
Verbose level between 0 and 2. |
utility function for formating
List with:
– descriptive table according to scheme defined in 'def_measures' (usually created by #' 'createDefMeasures()' and potentially modified)
– indication of tests used
under continuous developement
Roland Rapold
none
other utility-functions in this R-package
if(require("car")) { # sample data 'Mroz' from package 'car' require("car") str(Mroz) # insert attribute 'i' for population size Mroz <- merge(data.frame(i=as.factor(1)), Mroz) str(Mroz) # reference list for variable labels var.list <- data.frame(var_name=c("i", "lfp", "k5", "k618", "wc", "lwg", "inc"), var_label=c("population", "employed", "# children to 5", "# children 6-18", "wife college", "log expected wage", "family income excl. wife")) # create definition-table without variable for groups Mroz_hc <- Mroz[ , -which(colnames(Mroz)=="hc")] # variation 1: default, no adjustments def.measures.1 <- createDefMeasures(d.data=Mroz_hc) print(def.measures.1) # variation 2: apply variable labels def.measures.2 <- createDefMeasures(d.data=Mroz_hc, var.list=var.list) def.measures.2[2, 6] <- -2 def.measures.2[9, 6] <- -1 print(def.measures.2) # run different scenarios with modified data # - variation 1: default, no adjustments descrTable1 <- NULL descrTable1 <- descrTable(def.measures = def.measures.1, sub.d1 = subset(Mroz, hc=="no"), sub.d2 = subset(Mroz, hc=="yes"), sub.d3 = Mroz, group.size.total = 3, test.gr = c(1, 2)) print(descrTable1) descrTable2 <- descrTable(def.measures = def.measures.2, sub.d1 = subset(Mroz, hc=="no"), sub.d2 = subset(Mroz, hc=="yes"), sub.d3 = Mroz, test.gr = c(1, 2), lang="en") print(descrTable2) if(require("doBy")) { # - variation 1: verify statistics print(doBy::summaryBy(k5+k618+age+lwg+inc~hc, data=Mroz, FUN=c(mean, median, sum))) print(table(Mroz$lfp, Mroz$hc, dnn=c("lfp", "hc"))) print(table(Mroz$wc, Mroz$hc, dnn=c("lfp", "hc"))) } # - variation 2: insert some missing values for 'lfp' # 3 at Mroz$lfp where hc='no' n1 <- sample(1:length(Mroz[Mroz$hc=="no", "lfp"]), 3) Mroz[Mroz$hc=="no", "lfp"][n1] <- NA # 2 at Mroz$lfp where hc='yes' n2 <- sample(1:length(Mroz[Mroz$hc=="yes", "lfp"]), 2) Mroz[Mroz$hc=="yes", "lfp"][n2] <- NA descrTable3 <- descrTable(def.measures = def.measures.2, sub.d1 = subset(Mroz, hc=="no"), sub.d2 = subset(Mroz, hc=="yes"), sub.d3 = Mroz, test.gr = c(1, 2), lang="en") print(descrTable3) # - variation 3: insert some missing values for 'age' # 1 at Mroz$lfp where hc='no' n3 <- sample(1:length(Mroz[Mroz$hc=="no", "age"]), 1) Mroz[Mroz$hc=="no", "age"][n3] <- NA # 5 at Mroz$lfp where hc='no' n4 <- sample(1:length(Mroz[Mroz$hc=="yes", "age"]), 5) Mroz[Mroz$hc=="yes", "age"][n4] <- NA descrTable4 <- descrTable(def.measures = def.measures.2, sub.d1 = subset(Mroz, hc=="no"), sub.d2 = subset(Mroz, hc=="yes"), sub.d3 = Mroz, test.gr = c(1, 2), lang="en") print(descrTable4) # - variation 4: provoke warnings for small sample size Mroz_ <- Mroz[1:15, ] descrTable5 <- descrTable(def.measures = def.measures.2, sub.d1 = subset(Mroz_, hc=="no"), sub.d2 = subset(Mroz_, hc=="yes"), sub.d3 = Mroz_, test.gr = c(1, 2), lang="en", only.first.label=TRUE) print(descrTable5) # - variation 5: compare 4 groups Mroz[Mroz$wc=="no" & Mroz$hc=="no", "wchc"] <- "no-no" Mroz[Mroz$wc=="yes" & Mroz$hc=="no", "wchc"] <- "yes-no" Mroz[Mroz$wc=="no" & Mroz$hc=="yes", "wchc"] <- "no-yes" Mroz[Mroz$wc=="yes" & Mroz$hc=="yes", "wchc"] <- "yes-yes" descrTable6 <- descrTable(def.measures = def.measures.2, sub.d1 = subset(Mroz, wchc=="no-no"), sub.d2 = subset(Mroz, wchc=="no-yes"), sub.d3 = subset(Mroz, wchc=="yes-no"), sub.d4 = subset(Mroz, wchc=="yes-yes"), test.gr=c(1, 2 , 3, 4), only.first.label=TRUE) print(descrTable6) descrTable7 <- descrTable(def.measures = def.measures.2, sub.d1 = subset(Mroz, wchc=="no-no"), sub.d2 = subset(Mroz, wchc=="no-yes"), sub.d3 = subset(Mroz, wchc=="yes-no"), sub.d4 = subset(Mroz, wchc=="yes-yes"), only.first.label=TRUE) print(descrTable7) }