I am New to R studio and Have this code that won't run

cces18D <- svydesign(id = ~1, data = cces18, weights = ~commonweight)
m2 <- svyglm(repubtax ~ CC18_325d + ideo5 + CC18_325d, design = cces18D,family = "quasibinomial")
summary(m2)
predict.frame <- expand.grid(CC18_325d = levels(cces18$CC18_325d), ideo5 = levels(cces18$ideo5))
prediction <- predict.glm(m2, newdata = predict.frame, type = "response", se.fit = T)
prediction <- as.tibble(cbind(prediction,predict.frame))
prediction <- mutate(prediction, upr = fit + se.fit1.96, lwr = fit - se.fit1.96 )
p2 <- ggplot(data = prediction, aes(x = CC18_325d, y = fit, color = ideo5, shape = ideo5))
p2 + geom_pointrange(aes(ymin = lwr, ymax = upr))

Error in eval(family$initialize) : y values must be 0 <= y <= 1

  1. stop("y values must be 0 <= y <= 1")

  2. eval(family$initialize)

  3. eval(family$initialize)

  4. glm.fit(x = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...

  5. eval(call(if (is.function(method)) "method" else method, x = X, y = Y, weights = weights, start = start, etastart = etastart, mustart = mustart, offset = offset, family = family, control = control, intercept = attr(mt, "intercept") > 0L, singular.ok = singular.ok))

  6. eval(call(if (is.function(method)) "method" else method, x = X, y = Y, weights = weights, start = start, etastart = etastart, mustart = mustart, offset = offset, family = family, control = control, intercept = attr(mt, "intercept") > 0L, singular.ok = singular.ok))

  7. glm(formula = repubtax ~ CC18_325d + ideo5 + CC18_325d, family = "quasibinomial", weights = .survey.prob.weights, data = data)

  8. eval(g)

  9. eval(g)

  10. eval(substitute(expr), data, enclos = parent.frame())

  11. eval(substitute(expr), data, enclos = parent.frame())

  12. with.default(list(data = data), eval(g))

  13. with(list(data = data), eval(g))

  14. svyglm.survey.design(...)

  15. survey::svyglm(...)

  16. svyglm(repubtax ~ CC18_325d + ideo5 + CC18_325d, design = cces18D, family = "quasibinomial")

It seems the values of repubtax are not in the range 0 to 1. How was the object cces18D made? Can you inspect the contents and determine the values of repubtax?

I created a svydesign to create cces18D

Making cces18D with syvdesign seems to be the correct approach. Can you see the values of repubtax? Are they in the range 0 - 1?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.