2

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?

Mathdragon
  • 92
  • 11
  • 1
    The problem is caused by the variable `avg.ed` which contains NA values. You can see it from here: `dclus1r$variables$avg.ed` – Lstat Jan 10 '22 at 09:41
  • Interesting. I also have variables with missing values. But why does it work with the unraked data with `survey::svyolr` and without weights with `mass:polr(mealcat~avg.ed+mobility+stype, data=dclus1r$variables)`? The raking does not use `ave.ed`. `Svyolr` default is `na.action = na.omit`. I don't think that exluding the NA from the `svydesign` is the correct solution for standard error calculation but I might be wrong. – Mathdragon Jan 10 '22 at 21:29

1 Answers1

1

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")

Anthony Damico
  • 5,779
  • 7
  • 46
  • 77