Skip to content

Commit c2f6144

Browse files
residual degrees of freedom
1 parent 060f187 commit c2f6144

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export(ols_correlations)
8787
export(ols_eigen_cindex)
8888
export(ols_fpe)
8989
export(ols_get_data)
90+
export(ols_get_df)
9091
export(ols_get_formula)
9192
export(ols_get_interaction_terms)
9293
export(ols_get_variables)

R/ols-model-info.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,20 @@ ols_get_variables <- function(model) {
8787
ols_get_data <- function(model) {
8888
model$model
8989
}
90+
91+
92+
#' Degrees of freedom
93+
#'
94+
#' Returns model/residual degrees of freedom.
95+
#'
96+
#' @param model An object of class \code{lm}.
97+
#'
98+
#' @examples
99+
#' model <- lm(mpg ~ wt + cyl * hp * disp + gear * drat, data = mtcars)
100+
#' ols_get_df(model)
101+
#'
102+
#' @export
103+
#'
104+
ols_get_df <- function(model) {
105+
model$df.residual
106+
}

R/utils.R

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,6 @@ ols_get_terms <- function(model) {
9494
attr(model$terms, 'term.label')
9595
}
9696

97-
ols_get_variables <- function(model) {
98-
vars <- names(model$model)
99-
n <- length(vars)
100-
resp <- vars[1]
101-
preds <- vars[2:n]
102-
list(response = resp, predictors = preds)
103-
}
104-
105-
ols_get_data <- function(model) {
106-
model$model
107-
}
108-
109-
ols_get_df <- function(model) {
110-
model$df.residual
111-
}
112-
11397
ols_get_intercept <- function(model) {
11498
model$coefficients[[1]]
11599
}

man/ols_get_df.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-model-info.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ test_that("model data is returned", {
4747
expect_equal(want, got)
4848
})
4949

50+
test_that("residual degrees of freedom is returned", {
51+
model <- lm(mpg ~ wt * cyl + vs * hp * gear + carb, data = mtcars)
52+
want <- 20
53+
got <- ols_get_df(model)
54+
expect_equal(want, got)
55+
})
56+

0 commit comments

Comments
 (0)