diff --git a/articles/cocoon.html b/articles/cocoon.html index c00f2b3..250c95a 100644 --- a/articles/cocoon.html +++ b/articles/cocoon.html @@ -379,6 +379,158 @@

ANOVAs
+

Linear models +

+

The format_stats() function can also input objects +returned by the lm() and glm() functions. It +can report overall model statistics (e.g., R-squared, AIC) and +term-specific statistics (e.g., coefficients, p-values).

+

Let’s start by creating a linear model and generalized linear +model:

+
+lm_mpg_cyl_hp <- lm(mpg ~ cyl * hp, data = mtcars)
+summary(lm_mpg_cyl_hp)
+#> 
+#> Call:
+#> lm(formula = mpg ~ cyl * hp, data = mtcars)
+#> 
+#> Residuals:
+#>    Min     1Q Median     3Q    Max 
+#> -4.778 -1.969 -0.228  1.403  6.491 
+#> 
+#> Coefficients:
+#>              Estimate Std. Error t value Pr(>|t|)    
+#> (Intercept) 50.751207   6.511686   7.794 1.72e-08 ***
+#> cyl         -4.119140   0.988229  -4.168 0.000267 ***
+#> hp          -0.170680   0.069102  -2.470 0.019870 *  
+#> cyl:hp       0.019737   0.008811   2.240 0.033202 *  
+#> ---
+#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+#> 
+#> Residual standard error: 2.974 on 28 degrees of freedom
+#> Multiple R-squared:  0.7801, Adjusted R-squared:  0.7566 
+#> F-statistic: 33.11 on 3 and 28 DF,  p-value: 2.386e-09
+glm_am_cyl_hp <- glm(am ~ cyl * hp, data = mtcars, family = binomial)
+summary(glm_am_cyl_hp)
+#> 
+#> Call:
+#> glm(formula = am ~ cyl * hp, family = binomial, data = mtcars)
+#> 
+#> Coefficients:
+#>               Estimate Std. Error z value Pr(>|z|)  
+#> (Intercept)  6.1841091  4.8991403   1.262   0.2068  
+#> cyl         -1.7492046  0.8392287  -2.084   0.0371 *
+#> hp           0.0236170  0.0537369   0.439   0.6603  
+#> cyl:hp       0.0005349  0.0067365   0.079   0.9367  
+#> ---
+#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+#> 
+#> (Dispersion parameter for binomial family taken to be 1)
+#> 
+#>     Null deviance: 43.230  on 31  degrees of freedom
+#> Residual deviance: 28.619  on 28  degrees of freedom
+#> AIC: 36.619
+#> 
+#> Number of Fisher Scoring iterations: 5
+

To extract overall model statistics from format_stats(), +pass the lm or glm object but omit any +terms.

+ ++++ + + + + + + + + + + + + + + + + + + + + + + +
CodeOutput
format_stats(lm_mpg_cyl_hp) +R2 = 0.757, F(3, 28) = 33.113, +p < .001
format_stats(lm_mpg_cyl_hp, full = FALSE) +R2 = 0.757, p < .001
format_stats(glm_am_cyl_hp)Deviance = 28.619, χ2 = 14.611, AIC = +36.619
format_stats(glm_am_cyl_hp, full = FALSE)Deviance = 28.619, AIC = 36.619
+

To extract term-specific statistics, pass the object and a character +string describing which term to extract. Apply summary() to +your aov object and copy the text of the term you want to +extract. Then you can format the number of digits of coefficients with +digits and digits of p-values with pdigits. +Include the leading zeros for coefficients and p-values with +pzero = TRUE. Remove italics with +italics = FALSE. With dfs, format degrees of +freedom as parenthetical (par) or subscripts +(sub) or remove them (none).

+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CodeOutput
format_stats(lm_mpg_cyl_hp, term = "cyl") +β = -4.119, SE = 0.988, t = -4.168, p +< .001
format_stats(lm_mpg_cyl_hp, term = "cyl:hp") +β = 0.020, SE = 0.009, t = 2.240, p = +.033
format_stats(glm_am_cyl_hp, term = "cyl") +β = -1.749, SE = 0.839, z = -2.084, p = +.037
format_stats(lm_mpg_cyl_hp, term = "cyl", digits = 2, pdigits = 2) +β = -4.12, SE = 0.99, t = -4.17, p < +.01
format_stats(lm_mpg_cyl_hp, term = "cyl", pzero = TRUE) +β = -4.119, SE = 0.988, t = -4.168, p +< 0.001
format_stats(lm_mpg_cyl_hp, term = "cyl", italics = FALSE)β = -4.119, SE = 0.988, t = -4.168, p < .001
format_stats(lm_mpg_cyl_hp, term = "cyl", dfs = "sub") +β = -4.119, SE = 0.988, t = -4.168, p +< .001
+
+

Bayes factors

The format_stats() function can also extract and format @@ -396,7 +548,7 @@

Bayes factors
+
 bf_corr <- BayesFactor::correlationBF(mtcars$mpg, mtcars$disp)
 bf_ttest <- BayesFactor::ttestBF(mtcars$vs, mtcars$am)
 bf_lm <- BayesFactor::lmBF(mpg ~ am, data = mtcars)
diff --git a/index.html b/index.html index 3c8ffbe..47576c6 100644 --- a/index.html +++ b/index.html @@ -130,6 +130,8 @@

Functions and formatting typest.test() and wilcox.test(), including one-sample, two-sample independent, and paired tests)
  • ANOVAs from aov()
  • +
  • Linear models from lm() and generalized linear models from glm() +
  • Bayes factors (output from {BayesFactor} package)
  • diff --git a/pkgdown.yml b/pkgdown.yml index 761ab8d..77bc706 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: cocoon: cocoon.html -last_built: 2024-11-27T18:38Z +last_built: 2024-12-01T22:58Z urls: reference: https://jeffreyrstevens.github.io/cocoon/reference article: https://jeffreyrstevens.github.io/cocoon/articles diff --git a/reference/format_bf.html b/reference/format_bf.html index ea256cb..79b54eb 100644 --- a/reference/format_bf.html +++ b/reference/format_bf.html @@ -131,6 +131,7 @@

    See alsoformat_stats.aov(), format_stats.easycorrelation(), format_stats.htest(), +format_stats.lm(), format_ttest()

    diff --git a/reference/format_corr.html b/reference/format_corr.html index 430dfe9..a33b6fe 100644 --- a/reference/format_corr.html +++ b/reference/format_corr.html @@ -108,6 +108,7 @@

    See alsoformat_stats.aov(), format_stats.easycorrelation(), format_stats.htest(), +format_stats.lm(), format_ttest()

    diff --git a/reference/format_stats.BFBayesFactor.html b/reference/format_stats.BFBayesFactor.html index 7c24704..729ecbd 100644 --- a/reference/format_stats.BFBayesFactor.html +++ b/reference/format_stats.BFBayesFactor.html @@ -132,6 +132,7 @@

    See alsoformat_stats.aov(), format_stats.easycorrelation(), format_stats.htest(), +format_stats.lm(), format_ttest()

    diff --git a/reference/format_stats.aov.html b/reference/format_stats.aov.html index 2f3ce36..ac90b52 100644 --- a/reference/format_stats.aov.html +++ b/reference/format_stats.aov.html @@ -122,6 +122,7 @@

    See alsoformat_stats.BFBayesFactor(), format_stats.easycorrelation(), format_stats.htest(), +format_stats.lm(), format_ttest()

    diff --git a/reference/format_stats.easycorrelation.html b/reference/format_stats.easycorrelation.html index 419300f..394b296 100644 --- a/reference/format_stats.easycorrelation.html +++ b/reference/format_stats.easycorrelation.html @@ -124,6 +124,7 @@

    See alsoformat_stats.BFBayesFactor(), format_stats.aov(), format_stats.htest(), +format_stats.lm(), format_ttest()

    @@ -147,7 +148,7 @@

    Examples # Format Kendall's tau for LaTeX format_stats(test_corr2, type = "latex") -#> [1] "$τ$ = -.77, $p$ < .001" +#> [1] "$\\rho$ = -.77, $p$ < .001"