【问题标题】:Verify model assumptions with tidymodels使用 tidymodels 验证模型假设
【发布时间】:2021-09-06 12:19:06
【问题描述】:

在 tidymodels 领域之外,很容易验证模型假设。 例如,对于线性回归(函数 lm),包 performance 创建可理解的图形和简单的函数(check_heteroscedasticity())来验证假设线性回归模型:

  • 残差的正态性
  • 残差的独立性
  • 残差的同质性
  • 变量的非共线性。

在 tidymodels 宇宙中是否有等效包来验证模型的假设? Tidymodels 包创建 parnsnip 对象,所以像 performance 这样的旧模型评估包是没用的。

感谢您的帮助

【问题讨论】:

  • 我会说infer 就是为此目的而设计的;看看hypothesise 函数。
  • 请注意,您的术语并不“正确”,即您不想检查您的假设,您想检查您的模型假设 (!)。

标签: r tidymodels


【解决方案1】:

您使用 {parsnip} 或其他 {tidymodels} 获得的拟合模型将包含您使用的任何引擎的基础拟合模型。

有时,适合的欧洲防风草对象将直接与您正在使用的功能一起使用。 {performance} 中的 check_model() 函数就是这种情况。

library(tidymodels)
library(performance)

lm_spec <- linear_reg() %>%
  set_mode("regression") %>%
  set_engine("lm")

lm_fit <- fit(lm_spec, mpg ~ ., data = mtcars)

lm_fit %>%
  check_model()

其他时候你会得到一个错误,因为函数不知道如何处理model_fit 对象。您可以使用extract_fit_engine(),它将提取引擎产生的拟合,然后可以与check_heteroscedasticity()一起使用。

lm_fit %>% 
  extract_fit_engine() %>%
  check_heteroscedasticity()
#> OK: Error variance appears to be homoscedastic (p = 0.188).

reprex package (v2.0.1) 于 2021-09-06 创建

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 2021-03-24
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    相关资源
    最近更新 更多