`broom::glance.lm()` 提取了什么假设? `summary.lm` 中的 F 统计量是什么?

发布于 2025-01-09 15:11:26 字数 796 浏览 1 评论 0 原文

broom::glance()使得比较不同模型变得非常容易。由于帮助文件没有指定统计数据或p 值指的是。 正在检验什么假设?

library(broom)
mod <- lm(mpg ~ wt + qsec, data = mtcars)
    glance(mod)
#> # A tibble: 1 x 12
#>   r.squared adj.r.squared sigma statistic  p.value    df logLik   AIC   BIC
#>       <dbl>         <dbl> <dbl>     <dbl>    <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1     0.826         0.814  2.60      69.0 9.39e-12     2  -74.4  157.  163.
#>   deviance df.residual  nobs
#>      <dbl>       <int> <int>
#> 1     195.          29    32

由 reprex 包于 2022 年 2 月 24 日创建 (v2.0.1)

The broom::glance()makes it very easy to compare different models. As the help file doesn't specify what the statistic or p-value refers to. what hypothesis is being tested?

library(broom)
mod <- lm(mpg ~ wt + qsec, data = mtcars)
    glance(mod)
#> # A tibble: 1 x 12
#>   r.squared adj.r.squared sigma statistic  p.value    df logLik   AIC   BIC
#>       <dbl>         <dbl> <dbl>     <dbl>    <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1     0.826         0.814  2.60      69.0 9.39e-12     2  -74.4  157.  163.
#>   deviance df.residual  nobs
#>      <dbl>       <int> <int>
#> 1     195.          29    32

Created on 2022-02-24 by the reprex package (v2.0.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2025-01-16 15:11:26

查看 glance.lm() 函数(见下文),该函数从 summary.lm() 中提取信息。 F 统计量及其相应的 P 值将当前模型与仅截距模型进行比较 如此处所示

glance(mod1)summary(mod1) 进行比较时,情况会变得很清楚,因为 glance(mod1) “整理”了摘要,其动机是包(参见小插图)

summary(mod)
#> Call:
#> lm(formula = mpg ~ wt + qsec, data = mtcars)
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -4.3962 -2.1431 -0.2129  1.4915  5.7486 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)  19.7462     5.2521   3.760 0.000765 ***
#> wt           -5.0480     0.4840 -10.430 2.52e-11 ***
#> qsec          0.9292     0.2650   3.506 0.001500 ** 
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 2.596 on 29 degrees of freedom
#> Multiple R-squared:  0.8264, Adjusted R-squared:  0.8144 
#> F-statistic: 69.03 on 2 and 29 DF,  p-value: 9.395e-12

glance.lm() 函数:

getAnywhere("glance.lm")
A single object matching ‘glance.lm’ was found
It was found in the following places
  registered S3 method for glance from namespace broom
  namespace:broom
with value

function (x, ...) 
{
    warn_on_subclass(x)
    int_only <- nrow(summary(x)$coefficients) == 1
    with(summary(x), tibble(r.squared = r.squared, adj.r.squared = adj.r.squared, 
        sigma = sigma, statistic = if (!int_only) {
            fstatistic["value"]
        }
        else {
            NA_real_
        }, p.value = if (!int_only) {
            pf(fstatistic["value"], fstatistic["numdf"], 
                fstatistic["dendf"], lower.tail = FALSE)
        }
        else {
            NA_real_
        }, df = if (!int_only) {
            fstatistic["numdf"]
        }
        else {
            NA_real_
        }, logLik = as.numeric(stats::logLik(x)), AIC = stats::AIC(x), 
        BIC = stats::BIC(x), deviance = stats::deviance(x), df.residual = df.residual(x), 
        nobs = stats::nobs(x)))
}

Looking at the glance.lm() function (see below), the function extracts information from summary.lm(). The F-statistic and its corresponding P-value compares the current model to an intercept-only model as indicated here.

It becomes clear when comparing glance(mod1) to summary(mod1) in that glance(mod1) "tidies" up the summary as motivated by the package (see vignette)

summary(mod)
#> Call:
#> lm(formula = mpg ~ wt + qsec, data = mtcars)
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -4.3962 -2.1431 -0.2129  1.4915  5.7486 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)  19.7462     5.2521   3.760 0.000765 ***
#> wt           -5.0480     0.4840 -10.430 2.52e-11 ***
#> qsec          0.9292     0.2650   3.506 0.001500 ** 
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 2.596 on 29 degrees of freedom
#> Multiple R-squared:  0.8264, Adjusted R-squared:  0.8144 
#> F-statistic: 69.03 on 2 and 29 DF,  p-value: 9.395e-12

The glance.lm() function:

getAnywhere("glance.lm")
A single object matching ‘glance.lm’ was found
It was found in the following places
  registered S3 method for glance from namespace broom
  namespace:broom
with value

function (x, ...) 
{
    warn_on_subclass(x)
    int_only <- nrow(summary(x)$coefficients) == 1
    with(summary(x), tibble(r.squared = r.squared, adj.r.squared = adj.r.squared, 
        sigma = sigma, statistic = if (!int_only) {
            fstatistic["value"]
        }
        else {
            NA_real_
        }, p.value = if (!int_only) {
            pf(fstatistic["value"], fstatistic["numdf"], 
                fstatistic["dendf"], lower.tail = FALSE)
        }
        else {
            NA_real_
        }, df = if (!int_only) {
            fstatistic["numdf"]
        }
        else {
            NA_real_
        }, logLik = as.numeric(stats::logLik(x)), AIC = stats::AIC(x), 
        BIC = stats::BIC(x), deviance = stats::deviance(x), df.residual = df.residual(x), 
        nobs = stats::nobs(x)))
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文