strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
608 stars 91 forks source link

sjp.glmer type "pred" error #324

Closed BenedettaCatitti closed 6 years ago

BenedettaCatitti commented 6 years ago

Hi,

My glmer model looks like this: y <-cbind(tot1$H, tot1$L) m1.1 <- glmer(y~ Fed.Unfed + year + smear.quality + Estimated.age + X1W.MWS + X1W.NT + X1W.PP + number.of.nestlings.per.nest + Altitude + sex + disturbance + (1| nest.ID), tot1, family=binomial(link=logit),control=glmerControl(optimizer="bobyqa")) And I have to say I really love the sjp package.

I was trying now to plot some predictive values with the type="pred", like this:

sjp.glmer(m1.1, type = "pred.fe", vars = "Altitude")

Anyway, when I put one of my explanatoy variables (such as Altitude, which is a numeric continuous variable), I get this error message:

Error in mutate_impl(.data, dots) : Column resp.y must be length 284 (the number of rows) or one, not 0 In addition: Warning messages: 1: Unknown columns: y 2: In min(new_value, na.rm = T) : no non-missing arguments to min; returning Inf

Any idea??

Thank you very much!

strengejacke commented 6 years ago

I think it's because y is a two-column variable (using cbind()), which causes problems with sjp.glmer(). Could you try plot_model()? The function call should look like this:

plot_model(m1.1, type = "pred", terms = "Altitude")
BenedettaCatitti commented 6 years ago

At this point I think it's that as well, because by applying plot_model(m1.1, type = "pred", terms = "Altitude"), it gives me this plot with two independent variables instead of response variable and one independent

Is there any way I can get solve this? prova.pdf

BenedettaCatitti commented 6 years ago

And it gives me this warning message..

Warning messages: 1: Unknown columns: y 2: Unknown columns: y 3: Unknown columns: y

strengejacke commented 6 years ago

try cbind() directly in the formula, or include y in the data frame for the model.

BenedettaCatitti commented 6 years ago

If I include y in the data frame I have a new error:

Error in mutate_impl(.data, dots) : Evaluation error: Argument 1 must be length 284, not 568.

So I guess it can't really deal with 2 columns variables..?

strengejacke commented 6 years ago

Ok, might be that marginal effect plot types (like "pred" or "int") can't cope with 2-column variables, however, the simple plot (type = "fe") should. I must see if I find a reproducible example to do some tests and dive deeper into this issue (which is almost certain an issue of ggeffects, which does all the work for marginal effect plots in sjPlot).

BenedettaCatitti commented 6 years ago

I could send you part of the data if you want!

2018-01-18 11:25 GMT+01:00 Daniel notifications@github.com:

Ok, might be that marginal effect plot types (like "pred" or "int") can't cope with 2-column variables, however, the simple plot should. I must see if I find a reproducible example to do some tests and dive deeper into this issue (which is almost certain an issue of ggeffects, which does all the work for marginal effect plots in sjPlot).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/strengejacke/sjPlot/issues/324#issuecomment-358603698, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah4pjBHp4TIAwsLKiNzXDCmB2APta9jqks5tLxwEgaJpZM4RhZQC .

strengejacke commented 6 years ago

Yes, that would be great, so I can re-fit your model to reproduce the error.

strengejacke commented 6 years ago

I looked a bit into this issue, but currently I don't know how to solve this. For marginal effects plots like type = "pred", I use expand.grid() to create a combination of possible values. This does not seem to work with matrix-columns (like cbind()). Maybe there is a way I'm not aware of, and at least not in the related function in ggeffects, which prepares the required predictor levels.

strengejacke commented 6 years ago

I think this problem should be solved with the latest update from ggeffects. Can you confirm this?

strengejacke commented 6 years ago

bump

strengejacke commented 6 years ago

I'll close this issue for now, but feel free to reopen if you still encounter any problems.