Closed bbjonz closed 5 years ago
Not sure what scale()
does here, but try sjmisc::center()
to center your variables. Does that help?
Hi Daniel,
It did help, thanks. But not sure why. The scale command is base R version of standardizing/centering and it produces exactly the same values and structure (dbl) that sjmisc::center() does. Strange one...
Are all packages up to date? For me, all your examples run fine w/o any error... I'm using R 3.6, and the latest sjPlot / ggeffects /insigh packages.
Yes, and have the devel version of sjPlot. I'm sure you know that R 3.6.0 dropped a few days ago, so I had to update/reinstall all packages after the update.
Which OS are you using?
bump
Sorry. Busy time. Mac 10.14.4. Same problem on Linux 18.04
I can test only on Windows, but your example here works fine. As sjmisc::center()
currently solves your problem, I'l close this issue. Maybe we can re-open if we have better possibilities to check what is going on.
Hi,
I just wanted to add a workaround solution to this thread. I ran into the same problem doing the same thing (adding a scaled version of a column to a data frame -- either by doing df$x_sc = scale(df$x)
, df['x_sc'] = scale(df$x)
, or df %>% mutate(x_sc = scale(x))
-- and fitting my model using that new column, and then when I run predict() or anything that calls it, I get the same error that Joe got about fitted with type "nmatrix.1" but type "numeric" was supplied
.
It seems like a legacy of how new columns are quickly added to data frames -- as a complete matrix (see this forum post), so I didn't trigger the error when I did my scaling on the fly when I was calling my model fitting function. My workaround is to add my new column this way:
df['x_sc'] = as.data.frame(scale(df$x))
This, by the way, did not work:
df$x_sc = as.data.frame(scale(df$x))
Hope that helps others out there, Gina
Had a weird error message from plot_model using a centered predictor in a logistic regression. Here's the code:
The error for the last plot command reads:
Thoughts? Thanks in advance.
Joe