我正在尝试使用 glmmLasso pacakage 并且能够运行模型并获得摘要输出并提取拟合值,但我想知道我是否/如何使用它进行预测?
我错过了一步吗?
例如:
library(glmmLasso)
library(tidyverse)
mt_tbl <- mtcars %>% as_tibble() %>%
mutate(cyl = factor(cyl))
glm_cars <- glmmLasso(mpg ~ hp + drat + wt,
data=mt_tbl,
rnd = list(cyl=~1),
family = gaussian(link = "identity"),
lambda = .9,
switch.NR = TRUE,
final.re = TRUE)
# These work
summary(glm_cars)
glm_cars$fitted.values
# I want this to work
predict(glm_cars, mt_tbl)
如果您不将
mtcars
转换为 tibble
,则代码可以正常使用 data.frame
like
library(glmmLasso)
library(tidyverse)
#Convert cyl to factor
mtcars$cyl <- factor(mtcars$cyl)
#Run the model using 'data.frame'
glm_cars <- glmmLasso(mpg ~ hp + drat + wt,
data=mtcars,
rnd = list(cyl=~1),
family = gaussian(link = "identity"),
lambda = .9,
switch.NR = TRUE,
final.re = TRUE)
# These work
summary(glm_cars)
glm_cars$fitted.values
# Predict using 'data.frame' works
predict(glm_cars, mtcars)