Re: Nested crosstabulation with pairwise significance tests?
Dear Dr. Kabacoff,
Thank you very, very much for your coaching!
I tried your second script. The formatting of the table looked right, but the numbers in the cells did not look right.
I wrote my own script (please see below) that does get the right numbers into the cells. But it is really clunky. I hope there is a more elegant way to do this in R.
Also, I am wondering how to do Tukeys pairwise tests to see whether the subpopulations of males vs. females within each region are different in terms of proportions who prefer different contact options. This would mean testing whether in Northeast Males and Females were different in terms of proportion who prefer the over the phone option (i. e., to see whether 11% vs 13% is a significant difference) etc.
I am not sure why your script does not give the right numbers. I am not sure how to interpret this: prop.table(t, 3) converts the cell counts in table t to proportions, where the proportions add up to 1.0 for the 3rd variable (C here). Replace the 3 with any index or vector of indexes to control the margins. But the error seemed to have occurred at that step.
Cheers,
YZK

#This script seems to get the right table printed.
library(Hmisc)
fcc.df = spss.get("FCC.Consumer.Survey.Fall.2009.sav")
t= table( fcc.df$cregion, fcc.df$sex, fcc.df$q35b)
tbase=t
for (i in (1: dim(tbase)[1])) {
for ( j in (1: dim(tbase)[2]) ) {
for ( k in (1: dim(tbase)[3])) {
tbase[i,j,k] = sum( t[i,j,])
print( c("i=", i, " j=",j, " k=", k))
#This print statement is unnecessary for the calculations just a diagnostic
}
}
}
#tbase holds the total number of respondents of a given gender in a given region
t3 = ftable (t/tbase, row.vars=3)
print ("Entries in cells are in percentages for easier readability")
#I wonder how to put % sign into table when printing
print( t3*100, digits = 1)
