Analyzing ordinal data with the survey
package, I encountered some issues when trying to use raked data. Without raking, svyolr()
works without any problem, but when I try to analyze after raking, svyolr encounters an error Error in if (any(y < 0 | y > 1)) stop("y values must be 0 <= y <= 1") : missing value where TRUE/FALSE needed
.
The problem can be reproduced with the example data set api:
library(survey)
data(api)
dclus1 <- svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
dclus1<-update(dclus1, mealcat=cut(meals,c(0,25,50,75,100)))
m<-svyolr(mealcat~avg.ed+mobility+stype, design=dclus1)
m #works without a problem
## population marginal totals for each stratum
pop.types <- data.frame(stype=c("E","H","M"), Freq=c(4421,755,1018))
pop.schwide <- data.frame(sch.wide=c("No","Yes"), Freq=c(1072,5122))
## Rake with the population totals
dclus1r<-rake(dclus1, list(~stype,~sch.wide), list(pop.types, pop.schwide))
m2 <-svyolr(mealcat~avg.ed+mobility+stype, design=dclus1r)
m2 # error encountered
Am I doing something wrong? Can svyolr
not handle raked or poststratified (same error message) data? I didn't see any mention in the help file and could not even find the if condition or error message in the code of survey:::svyolr.survey.design2
.
Is it possible to do this with survey
or any other package in R
?
you actually found a bug :-) version 4.2 has this fixed..you can use the development version of the survey
package until the update goes to CRAN by installing with install.packages("survey", repos="http://R-Forge.R-project.org")