[R] Three-way mosaic residual plot with survey data

Mast, Brent D Brent.D.Mast at hud.gov
Tue Dec 30 20:24:54 CET 2014


I want to produce a three-way mosaic residual plot with survey data. I'm using the mosaic function from the vcd package for the plot, and the svytable function from the survey package to produce the contingency table.
Here is my code for a two-way table (that works) and a three-way table that plots but I think is wrong.

dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)

# two-way plot
st2 <- svytable(~sch.wide+comp.imp,design=dclus1,round=TRUE)
mosaic(st2,main = "Two-Way Mosaic Plot", shade = TRUE, legend = TRUE)

# three-way plot
st3 <- svytable(~sch.wide+comp.imp+stype,design=dclus1,round=TRUE)
mosaic(st3,main = "Three-Way Mosaic Plot", shade = TRUE, legend = TRUE)

When I try to summarize the three-way svytable object "st3", I get the following error:
> summary(st3)
Error in svychisq.survey.design(~sch.wide + comp.imp + stype, design = dclus1,  :
  Only 2-way tables at the moment

It still produces the three-way mosaic plot. But I don't think it's plotting the residuals correctly because the error message indicates only two-way chi-square tests are allowed.

The vcd package will create a mosaic residual plot from a log-linear model estimated by the loglm function from the MASS package. But it won't accept a log-linear model created with the svyloglin function from the survey package.
I'm wondering if I could run a log-linear model with svyloglin and transform the output into a table format that the mosaic function will plot.

Any help would be appreciated.

Thanks, and happy New Year.

Brent Mast
Social Science Analyst
HUD Office of Policy Development & Research
Program Monitoring & Research Div.

	[[alternative HTML version deleted]]

More information about the R-help mailing list