在glmmLasso模型上进行预测

huangapple go评论61阅读模式
英文:

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 &lt;- mtcars %&gt;% as_tibble() %&gt;% 
  mutate(cyl = factor(cyl))

glm_cars &lt;- glmmLasso(mpg ~  hp + drat + wt,
                        data=mt_tbl,
                        rnd = list(cyl=~1),
                        family = gaussian(link = &quot;identity&quot;),
                        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 &lt;- factor(mtcars$cyl)

#Run the model using &#39;data.frame&#39;
glm_cars &lt;- glmmLasso(mpg ~  hp + drat + wt,
                      data=mtcars,
                      rnd = list(cyl=~1),
                      family = gaussian(link = &quot;identity&quot;),
                      lambda = .9,
                      switch.NR = TRUE,
                      final.re = TRUE)

# These work
summary(glm_cars)
glm_cars$fitted.values

# Predict using &#39;data.frame&#39; works
predict(glm_cars, mtcars)

huangapple
  • 本文由 发表于 2023年4月4日 12:21:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925498.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定