Skip to contents

This function generates random values from the expression of y, and keeps all the right hand side information in a data frame.

Arguments

n

Integer. Number of observations.

fit_model

Boolean. Whether or not to fit a null model to obtain the fitted values and the residuals. Default is TRUE.

test

Boolean. Whether or not to test the null model against the alternative model to obtain the test statistic and the p-value. Default is FALSE.

computed

List. Default is NULL. If it is provided, random variables or random closed form expression will use the values from the list, which makes the expression potentially deterministic.

Value

A data frame.

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)
dat
#>           y          x          e      .resid  .fitted
#> 1  2.181303 0.34361211  0.7196220  0.04673363 2.134570
#> 2  2.709697 0.50525009  0.9491690  0.63606571 2.073631
#> 3  3.336069 0.54693797  1.4899895  1.27815418 2.057914
#> 4  2.682229 0.31685982  1.2649687  0.53757303 2.144656
#> 5  2.316093 0.67233648  0.1917197  0.30545430 2.010638
#> 6  0.352242 0.36084107 -1.1388054 -1.77583238 2.128074
#> 7  1.124684 0.42776140 -0.4860573 -0.97816100 2.102845
#> 8  1.391063 0.54282316 -0.4464167 -0.66840227 2.059466
#> 9  2.890814 0.02153749  1.8688128  0.63481978 2.255994
#> 10 2.159453 0.23409623  0.8705559 -0.01640497 2.175858

test$gen(10, computed = list(e = dat$e))
#>            y          e          x      .resid   .fitted
#> 1  1.8513290  0.7196220 0.11782441  0.67867725 1.1726518
#> 2  2.6769460  0.9491690 0.48882608  0.25067664 2.4262694
#> 3  3.4897471  1.4899895 0.61792557  0.62724944 2.8624976
#> 4  3.4519712  1.2649687 0.69875040  0.31636582 3.1356054
#> 5  1.2983932  0.1917197 0.09722147  0.19535891 1.1030343
#> 6  0.1578863 -1.1388054 0.23938600 -1.42552308 1.5834094
#> 7  0.5492292 -0.4860573 0.03412225 -0.34059226 0.8898215
#> 8  1.8720756 -0.4464167 0.75239464 -1.44479406 3.3168697
#> 9  3.6836295  1.8688128 0.53189955  1.11181445 2.5718150
#> 10 2.8265758  0.8705559 0.59818938  0.03076689 2.7958089

test$gen(10, test = TRUE)
#>             y         x           e      .resid  .fitted test_name statistic
#> 1   1.0953586 0.3539549 -0.38388032 -0.50698122 1.602340    F-test 0.6208182
#> 2   1.3896059 0.5508355 -0.46464934 -0.18939569 1.579002    F-test 0.6208182
#> 3   1.5968128 0.7216158 -0.64553227  0.03805569 1.558757    F-test 0.6208182
#> 4  -0.6144918 0.3004186 -2.00516171 -2.22317787 1.608686    F-test 0.6208182
#> 5   2.3348543 0.5050097  0.57480978  0.75042050 1.584434    F-test 0.6208182
#> 6   2.0964468 0.6854306 -0.05879878  0.53340026 1.563047    F-test 0.6208182
#> 7   1.7458138 0.5190429 -0.04263452  0.16304358 1.582770    F-test 0.6208182
#> 8   1.3239188 0.8703345 -1.30389782 -0.21720916 1.541128    F-test 0.6208182
#> 9   1.7273424 0.7745808 -0.64721396  0.17486373 1.552479    F-test 0.6208182
#> 10  3.1093524 0.1006041  1.99862713  1.47698016 1.632372    F-test 0.6208182
#>      p_value
#> 1  0.4565906
#> 2  0.4565906
#> 3  0.4565906
#> 4  0.4565906
#> 5  0.4565906
#> 6  0.4565906
#> 7  0.4565906
#> 8  0.4565906
#> 9  0.4565906
#> 10 0.4565906