使用扫帚和tidyverse来总结r平方的gams

时间:2018-02-07 08:29:27

标签: r tidyverse gam mgcv

我发布了一个问题here并且能够重现Claus' answer以使用虹膜数据上的tidyverse计算添加剂模型中每个物种的多个r平方值。但是,包发生了更新,现在没有计算R-sq值。不知道为什么......
这是子句响应和输出

library(tidyverse)
library(broom)
iris %>% nest(-Species) %>% 
  mutate(fit = map(data, ~mgcv::gam(Sepal.Width ~ s(Sepal.Length, bs = "cs"), data = .)),
         results = map(fit, glance),
         R.square = map(fit, ~ summary(.)$r.sq)) %>%
  unnest(results) %>%
  select(-data, -fit)

#      Species  R.square       df    logLik      AIC      BIC deviance df.residual
# 1     setosa 0.5363514 2.546009 -1.922197 10.93641 17.71646 3.161460    47.45399
# 2 versicolor 0.2680611 2.563623 -3.879391 14.88603 21.69976 3.418909    47.43638
# 3  virginica 0.1910916 2.278569 -7.895997 22.34913 28.61783 4.014793    47.72143

然而,我的代码和输出产生了R.square <dbl [1]>

library(tidyverse)
library(broom)
iris %>% nest(-Species) %>% 
  mutate(fit = map(data, ~mgcv::gam(Sepal.Width ~ s(Sepal.Length, bs = "cs"), data = .)),
          results = map(fit, glance),
          R.square = map(fit, ~ summary(.)$r.sq)) %>%
   unnest(results) %>%
   select(-data, -fit)

     Species  R.square       df    logLik      AIC      BIC deviance
      <fctr>    <list>    <dbl>     <dbl>    <dbl>    <dbl>    <dbl>
1     setosa <dbl [1]> 2.396547 -1.973593 10.74028 17.23456 3.167966
2 versicolor <dbl [1]> 2.317501 -4.021222 14.67745 21.02058 3.438361
3  virginica <dbl [1]> 2.278569 -7.895997 22.34913 28.61783 4.014793

任何人都能提供有关原因的见解吗?

1 个答案:

答案 0 :(得分:5)

我和OP有dcp_options(见上面的评论)。我可以通过使用dcp_suboptions强制R平方成为双精度来解决这个问题。我不完全确定为什么它适用于Akrun ......?

sessionInfo