【问题标题】:Problems after broom update?刷机更新后出现问题?
【发布时间】:2021-02-26 14:29:13
【问题描述】:

我有这段代码可以同时运行多个线性模型,每个模型的每个级别都是分开的。首先,我使用filtergroup_by 对数据进行子集化,然后使用do() 构建模型并使用tidy() 显示输出

dados <- read.table("Rafael_bovo_dados2.txt", h=TRUE)
dim(dados)#dimensões da tabela
head(dados); str(dados)

df_lm <- dados %>%
       filter(Species == "Physalaemus_cuvieri") %>%
       group_by(Mountain_Range) %>%
       do(mod = lm(EWL_ug~as.factor(Altitude),data = .))

df_lm %>%
  tidy(mod)

最后一行用于返回一个表格,其中包含所有这些模型的汇总统计信息和其他结果,例如 this vignette 中的那些。但是,这现在会返回一个错误,指出不推荐使用 tidy。

Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) : 
  is.atomic(x) is not TRUE
In addition: Warning messages:
1: Data frame tidiers are deprecated and will be removed in an upcoming release of broom. 
2: `data_frame()` is deprecated as of tibble 1.1.0.
Please use `tibble()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 
3: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA
4: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA
5: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
  NAs introduced by coercion

如何更改代码以返回包含统计信息和 P 值的整个表?

【问题讨论】:

    标签: r broom


    【解决方案1】:

    经过一番挖掘,我能够修改代码:

    df_lm <- dados %>%
           filter(Species == "Physalaemus_cuvieri") %>%
           nest_by(Mountain_Range) %>%
          mutate(mod = list(lm(EWL_ug~as.factor(Altitude),data = data)))
    
    df_lm %>%
      summarise(broom::tidy(mod))
    

    现在它返回了我的预期:

    `summarise()` regrouping output by 'Mountain_Range' (override with `.groups` argument)
    # A tibble: 4 x 6
    # Groups:   Mountain_Range [2]
      Mountain_Range   term        estimate std.error statistic  p.value
      <chr>            <chr>          <dbl>     <dbl>     <dbl>    <dbl>
    1 Serra_da_Mantiq… (Intercept)   2.93       0.188    15.6   7.68e- 9
    2 Serra_da_Mantiq… as.factor(…  -0.497      0.226    -2.19  5.07e- 2
    3 Serra_do_Mar     (Intercept)   2.70       0.149    18.1   5.33e-13
    4 Serra_do_Mar     as.factor(…  -0.0669     0.201    -0.333 7.43e- 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 2020-09-04
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      相关资源
      最近更新 更多