Skip to contents

This function uses the data and the null model to generate null residuals. The null residuals are generated by first regressing random noises on the original regressors, then multiply the obtained residuals by original RSS divided by the current RSS. The results are the null residuals.

Arguments

dat

Data frame. A data frame that used to fit the model.

mod

Linear Model. The null model.

test

Boolean. Whether or not to use test on the newly generated data.

Value

A data frame with updated y, .resid, and potentially updated test result.

Examples


# Instantiate
x <- rand_uniform()
e <- rand_normal()
test <- vi_model(prm = list(x = x, e = e),
                 prm_type = list(x = "r", e = "r"),
                 formula = y ~ 1 + x + x^2 + e,
                 null_formula = y ~ x,
                 alt_formula = y ~ x + I(x^2))

dat <- test$gen(10)
test$null_resid(dat, test$fit(dat), test = TRUE)
#>           y          x          e     .resid  .fitted test_name statistic
#> 1  3.441043 0.39981093 -0.2018527  1.1069942 2.334049    F-test  1.590544
#> 2  1.956685 0.05564954  0.6577813 -0.6577916 2.614477    F-test  1.590544
#> 3  1.147591 0.93751792 -1.4748553 -0.7483271 1.895918    F-test  1.590544
#> 4  1.187821 0.66930164  0.5465937 -0.9266438 2.114464    F-test  1.590544
#> 5  2.633396 0.23329027  1.8163460  0.1636628 2.469733    F-test  1.590544
#> 6  2.497478 0.13328545  0.5711878 -0.0537396 2.551218    F-test  1.590544
#> 7  2.470786 0.43430630  1.8795511  0.1648445 2.305942    F-test  1.590544
#> 8  1.785301 0.90614375 -1.2087911 -0.1361807 1.921482    F-test  1.590544
#> 9  4.029171 0.64952762 -0.1792063  1.8985942 2.130577    F-test  1.590544
#> 10 1.550555 0.36554707  2.3814244 -0.8114129 2.361968    F-test  1.590544
#>     p_value null
#> 1  0.247652 TRUE
#> 2  0.247652 TRUE
#> 3  0.247652 TRUE
#> 4  0.247652 TRUE
#> 5  0.247652 TRUE
#> 6  0.247652 TRUE
#> 7  0.247652 TRUE
#> 8  0.247652 TRUE
#> 9  0.247652 TRUE
#> 10 0.247652 TRUE