0

I am attempting to run a multi-level regression and poststratification in R, and I keep getting an error that my dependent variable "must be integer values of 0 / 1 or logical". I ran the following

punitive.data <- within(punitive.data, punall <- as.integer(punall))

followed by

is.integer(punitive.data$punall)

which returned a response of TRUE.

Then I ran

mrp.simple <- mrp(punall ~ statenum + f.race , data = punitive.data, population = census.data)

which returned the following error:

Error in checkResponse(response, response.varname) : 
'punall' must be integer values of 0 / 1 or logical.

I rechecked the variable type with the is.integer function and got a TRUE response again. The variable also shows as an integer in the Environment. All values in the variable are either 0 or 1.

Any advice or help would be greatly appreciate.

  • 2
    If this is a question about data types, a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) is going to be necessary to give meaningful help. Are you *sure* that that variable only has values of 0 or 1? Because your error message says it doesn't – camille Nov 07 '19 at 15:20

1 Answers1

0

You can solve it by doing the following

punitive.data$punall <- as.logical(punitive.data$punall)

And then this should work

 mrp.simple <- mrp(punall ~ statenum + f.race , data = punitive.data, population = census.data)

Note that if your data contains a value higher than 1 it will become TRUE.

dylanvanw
  • 3,029
  • 1
  • 8
  • 18