0
4

1 回答 1

1

您需要使用来从模型对象中extract_fit_engine()取出基础lm拟合对象。parsnip

library(tidymodels)
library(PoEdata)
library(car)

data("cps4_small")

lm_model <- linear_reg() %>% 
  set_engine("lm")

mod1 <- lm_model %>% 
  fit(wage ~ educ + black * female, data = cps4_small)

hyp <- c("black=0", "female=0", "black:female=0")

mod1 %>%
  extract_fit_engine() %>%
  linearHypothesis(hyp) %>%
  tidy()
#> # A tibble: 2 × 6
#>   res.df     rss    df sumsq statistic  p.value
#>    <dbl>   <dbl> <dbl> <dbl>     <dbl>    <dbl>
#> 1    998 135771.    NA   NA       NA   NA      
#> 2    995 130195.     3 5576.      14.2  4.53e-9

reprex 包于 2021-11-13 创建(v2.0.1)

于 2021-11-13T22:48:35.557 回答