cp_F {gspcr} | R Documentation |
Compute F statistic
Description
Computes the F statistic comparing two nested models.
Usage
cp_F(y, y_hat_restricted, y_hat_full, n = length(y), p_restricted = 0, p_full)
Arguments
y |
numeric vector storing the observed values on the dependent variable |
y_hat_restricted |
numeric vector storing the predicted values on |
y_hat_full |
numeric vector storing the predicted values on |
n |
numeric vector of length 1 storing the sample size used to train the models |
p_restricted |
numeric vector of length 1 storing the number of predictors involved in training the restricted model |
p_full |
numeric vector of length 1 storing the number of predictors involved in training the full model |
Details
Note that:
The full model is always the model with more estimated parameters, the model with more predictor variables.
The restricted model is the model with fewer estimated parameters.
The restricted model must be nested within the full model.
Value
numeric vector of length 1 storing the F-statistic
Author(s)
Edoardo Costantini, 2023
Examples
# Null vs full model
lm_n <- lm(mpg ~ 1, data = mtcars) # Fit a null model
lm_f <- lm(mpg ~ cyl + disp, data = mtcars) # Fit a full model
f_M <- cp_F(
y = mtcars$mpg,
y_hat_restricted = predict(lm_n),
y_hat_full = predict(lm_f),
p_full = 2
)
# Simpler vs more complex model
lm_f_2 <- lm(mpg ~ cyl + disp + hp + drat + qsec, data = mtcars) # a more complex full model
f_change_M <- cp_F(
y = mtcars$mpg,
y_hat_restricted = predict(lm_f),
y_hat_full = predict(lm_f_2),
p_restricted = 2,
p_full = 5
)