I've fit a model using the glmer
function from the lme4
package. Because my predictor variables are on very different scales, I needed to rescale all of them in order to make my model converge. I did so using arm::rescale
, which standardizes by centering on the mean and dividing by two standard deviations. My model is a binomial model with a proportion as the response variable, so I included a weights argument that represents the maximum possible counts. The model is:
M1 <- glmer(Y~A+B+C+D+A*B+(A|Territory)+(1|RowID), data=data, family=binomial,
weights=WeightingFactor)
In this model, A, B, C, and D are the four rescaled predictors. I would like to present the coefficients and confidence intervals for these predictors on their original scale. I would also like to plot the model for each of the predictors on their original scale.
I've read several threads (1, 2, 3), but I must admit that given my relatively basic understanding of R, I haven't been able to adapt them to my situation and make the code work. For example, in thread 1 linked above, I have adapted the code provided to my situation, but I get stuck relatively early on.
database <- data
# Scale data
database$A <- arm::rescale(data$a)
database$B <- arm::rescale(data$b)
database$C<-arm::rescale(data$c)
database$D<-arm::rescale(data$d)
# Make model
model.1 <- glmer(PantingProp ~ A + B + C + D+ A*B +(A|Territory), database, family = binomial, weights=WeightingFactor)
# make new data frame with all values set to their mean
xA <- as.data.frame(lapply(lapply(database[, -1], mean), rep, 100))
I get the following error:
The rest of the answer to that question requires me to have the xA data frame, and so I'm stuck. I'm also unsure if the answer there can be adapted to my situation, given that I have used a different function to scale my predictors than was used by the author of that post. Any guidance (whether in regards to how to make the above code work, or a different approach to unscaling my predictors) would be appreciated. If additional information would be helpful to address this problem, please let me know!
lapply(lapply( ...
twice. Why? $\endgroup$ – kjetil b halvorsen♦ Mar 14 '20 at 15:42