英文:
Predicting on a glmmLasso model
问题
我想使用glmmLasso包,已经可以运行模型并得到摘要输出以及提取拟合值,但我想知道如何使用它进行预测?
我是否漏掉了一步?
例如:
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)
# 这些可以运行
summary(glm_cars)
glm_cars$fitted.values
# 我希望这个可以运行
predict(glm_cars, mt_tbl)
英文:
I'm trying to use the glmmLasso pacakage and am able to run a model and get a summary output and extract the fitted values, but I'm wondering if/how I can make predictions with it?
Am I missing a step?
For example:
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)
答案1
得分: 1
如果不将`mtcars`转换为`tibble`,代码在使用`data.frame`时可以正常工作,如下所示:
英文:
If you do not convert mtcars
to tibble
, the code works fine with 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论