crosstabs(formula, data=sys.parent(), margin=<<see below>>, subset, na.action=na.fail, drop.unused.levels=T)
Each element of the list gives a vector of dimension numbers to not sum over when computing denominators for various proportions of cell count to marginal totals. E.g., 1 means to calculate row sums and integer(0) means to calculate the grand sum. The default for a two way crosstabulation is list("Row%"=1, "Col%"=2, "Total%"=integer(0)) and that for a one way table is list("Total%"=integer(0)). For higher dimensional crosstabulations, the default results in printing the row and column proportions for each layer-- list("N/RowTotal" = setdiff(i, 2), "N/ColTotal" = setdiff(i, 1), "N/Total" = integer(0)) where i is 1:number.of.factors. The margin argument here is similar to that in loglin.
crosstabs(~Solder+Opening, data=solder, subset = skips>10)# produces the following output: Call: crosstabs( ~ Solder + Opening, data = solder, subset = skips > 10) 158 cases in table +----------+ |N | |N/RowTotal| |N/ColTotal| |N/Total | +----------+ Solder |Opening |S |M |L |RowTotl| -------+-------+-------+-------+-------+ Thin |99 |15 | 9 |123 | |0.805 |0.122 |0.073 |0.78 | |0.805 |0.577 |1.000 | | |0.627 |0.095 |0.057 | | -------+-------+-------+-------+-------+ Thick |24 |11 | 0 |35 | |0.686 |0.314 |0.000 |0.22 | |0.195 |0.423 |0.000 | | |0.152 |0.070 |0.000 | | -------+-------+-------+-------+-------+ ColTotl|123 |26 |9 |158 | |0.778 |0.165 |0.057 | | -------+-------+-------+-------+-------+ Test for independence of all factors Chi^2 = 9.18309 d.f.= 2 (p=0.01013719) Yates' correction not used Some expected values are less than 5, don't trust stated p-value
# example #2
data <- data.frame(Pet=c("Dog","Dog","Cat","Cat","Cat"), Food=c("Wet","Wet","Dry","Wet",NA)) crosstabs(data=data, na.action=na.omit)
# produces the following output: Call: crosstabs(data = data, na.action = na.omit) 4 cases in table Dropping 1 cases because of missing values +----------+ |N | |N/RowTotal| |N/ColTotal| |N/Total | +----------+ Pet |Food |Dry |Wet |RowTotl| -------+-------+-------+-------+ Cat |1 |1 |2 | |0.50 |0.50 |0.5 | |1.00 |0.33 | | |0.25 |0.25 | | -------+-------+-------+-------+ Dog |0 |2 |2 | |0.00 |1.00 |0.5 | |0.00 |0.67 | | |0.00 |0.50 | | -------+-------+-------+-------+ ColTotl|1 |3 |4 | |0.25 |0.75 | | -------+-------+-------+-------+ Test for independence of all factors Chi^2 = 1.333333 d.f.= 1 (p=0.2482131) Yates' correction not used Some expected values are less than 5, don't trust stated p-value