Skip to contents

This function will be called after an instance is built. User input will be stored in the environment. The response variable of this model is y. The formula of y is defined in POLY_MODEL$formula, the null formula is defined in POLY_MODEL$null_formula, the alternative is defined in POLY_MODEL$alt_formula. The formula for the raw orthogonal polynomial term is defined in POLY_MODEL$raw_z_formula, and the scaled orthogonal polynomial term is defined in POLY_MODEL$z_formula.

Arguments

shape

Integer. The shape of the orthogonal polynomial used in the model. Note it should be a value between 1 to 4. Default is shape = 1.

sigma

Positive numeric. Default is sigma = 1.

include_z

Boolean. Whether or not to include z in the formula of y. Default is include_z = TRUE.

x

Random variable or closed form expression. Default is x = rand_uniform(-1, 1, env = new.env(parent = parent.env(self))).

e

Random variable or closed form expression. Default is e = rand_normal(0, sigma, env = new.env(parent = parent.env(self))).

Value

Return the object itself.

Examples


# Instantiate
x <- rand_uniform()
e <- rand_normal(sigma = 0.5)

test <- poly_model(shape = 1, x = x, e = e)

test
#> 
#> ── <POLY_MODEL object>
#> y = 1 + x + include_z * z + e
#>  - x: <RAND_UNIFORM object>
#>    [a: 0, b: 1]
#>  - z: <CLOSED_FORM object>
#>    EXPR = (raw_z - min(raw_z))/max(raw_z - min(raw_z)) * 2 - 1
#>     - raw_z: <CLOSED_FORM object>
#>       EXPR = hermite(shape)((x - min(x))/max(x - min(x)) * 4 - 2)
#>        - x: <RAND_UNIFORM object>
#>          [a: 0, b: 1]
#>  - e: <RAND_NORMAL object>
#>    [mu: 0, sigma: 0.5]
#> Parameters:
#>  - shape: 1
#>  - include_z: TRUE
#>  - sigma: 1 

# Generate data
test$gen(10)
#>             y          x      raw_z          z           e      .resid
#> 1  2.82918402 0.99206147  3.0000000  1.0000000 -0.16287746  0.43127384
#> 2  1.18415371 0.32417575 -0.4060480 -0.7046933  0.56467131  0.14006221
#> 3  1.45230931 0.23659775  0.2859441 -0.3583581  0.57406970  0.58574029
#> 4  1.10669575 0.64739654 -0.6748962 -0.8392492  0.29854844 -0.59257122
#> 5  0.12738603 0.40899947 -0.8246092 -0.9141791 -0.36743434 -1.08864498
#> 6  0.91455446 0.52503913 -0.9960829 -1.0000000  0.38951532 -0.53669143
#> 7  3.24321498 0.92981657  2.0338006  0.5164267  0.79697167  0.97147655
#> 8  1.57651064 0.02784324  3.0000000  1.0000000 -0.45133259  1.13309149
#> 9  0.05887894 0.40170245 -0.7983379 -0.9010306 -0.44179295 -1.14236085
#> 10 0.95571796 0.23192334  0.3302999 -0.3361585  0.05995314  0.09862408
#>      .fitted
#> 1  2.3979102
#> 2  1.0440915
#> 3  0.8665690
#> 4  1.6992670
#> 5  1.2160310
#> 6  1.4512459
#> 7  2.2717384
#> 8  0.4434191
#> 9  1.2012398
#> 10 0.8570939

# Generate lineup
test$gen_lineup(10, k = 3)
#>             y           x      raw_z          z           e      .resid
#> 1   0.5661146 0.464207984 -0.8315598 -0.9158039  0.01771045 -0.72833381
#> 2  -0.6533803 0.386998348 -0.9999500 -1.0000000 -1.04037869 -1.84380747
#> 3   1.5131674 0.002796276  3.0000000  1.0000000 -0.48962883  0.84035936
#> 4   2.1179047 0.768493104  3.0000000  1.0000000 -0.65058840  0.41350599
#> 5   0.7062670 0.431980628 -0.9414075 -0.9707284  0.24501472 -0.54476286
#> 6   3.1096976 0.724419444  2.1320477  0.5660184  0.81925975  1.46467745
#> 7   0.6738162 0.536686856 -0.3774092 -0.6887257 -0.17414497 -0.71827989
#> 8   0.2255530 0.494252309 -0.6780956 -0.8390708 -0.42962847 -1.10937278
#> 9   2.7763821 0.680455114  1.3718759  0.1859278  0.90999921  1.19059319
#> 10  1.7428003 0.028456856  2.4817662  0.7408799 -0.02653640  1.03542082
#> 11  1.3539328 0.464207984 -0.8315598 -0.9158039  0.01771045  0.05948446
#> 12  0.2050582 0.386998348 -0.9999500 -1.0000000 -1.04037869 -0.98536897
#> 13 -0.1714869 0.002796276  3.0000000  1.0000000 -0.48962883 -0.84429503
#> 14  2.2200728 0.768493104  3.0000000  1.0000000 -0.65058840  0.51567408
#> 15  3.3877251 0.431980628 -0.9414075 -0.9707284  0.24501472  2.13669531
#> 16  0.8792281 0.724419444  2.1320477  0.5660184  0.81925975 -0.76579210
#> 17  2.8587838 0.536686856 -0.3774092 -0.6887257 -0.17414497  1.46668776
#> 18  0.5664912 0.494252309 -0.6780956 -0.8390708 -0.42962847 -0.76843462
#> 19  0.3700902 0.680455114  1.3718759  0.1859278  0.90999921 -1.21569872
#> 20  1.1084273 0.028456856  2.4817662  0.7408799 -0.02653640  0.40104782
#> 21  2.5209435 0.464207984 -0.8315598 -0.9158039  0.01771045  1.22649515
#> 22 -0.2402070 0.386998348 -0.9999500 -1.0000000 -1.04037869 -1.43063414
#> 23  1.2726077 0.002796276  3.0000000  1.0000000 -0.48962883  0.59979959
#> 24  0.4758463 0.768493104  3.0000000  1.0000000 -0.65058840 -1.22855243
#> 25  3.0939044 0.431980628 -0.9414075 -0.9707284  0.24501472  1.84287453
#> 26  2.2088480 0.724419444  2.1320477  0.5660184  0.81925975  0.56382785
#> 27  0.5499036 0.536686856 -0.3774092 -0.6887257 -0.17414497 -0.84219246
#> 28  0.7270716 0.494252309 -0.6780956 -0.8390708 -0.42962847 -0.60785420
#> 29  2.3191896 0.680455114  1.3718759  0.1859278  0.90999921  0.73340076
#> 30 -0.1497851 0.028456856  2.4817662  0.7408799 -0.02653640 -0.85716465
#>      .fitted test_name  statistic     p_value k  null
#> 1  1.2944484    F-test 20.1814245 0.002824028 3 FALSE
#> 2  1.1904271    F-test 20.1814245 0.002824028 3 FALSE
#> 3  0.6728081    F-test 20.1814245 0.002824028 3 FALSE
#> 4  1.7043987    F-test 20.1814245 0.002824028 3 FALSE
#> 5  1.2510298    F-test 20.1814245 0.002824028 3 FALSE
#> 6  1.6450202    F-test 20.1814245 0.002824028 3 FALSE
#> 7  1.3920961    F-test 20.1814245 0.002824028 3 FALSE
#> 8  1.3349258    F-test 20.1814245 0.002824028 3 FALSE
#> 9  1.5857889    F-test 20.1814245 0.002824028 3 FALSE
#> 10 0.7073795    F-test 20.1814245 0.002824028 3 FALSE
#> 11 1.2944484    F-test  0.4726027 0.513917579 1  TRUE
#> 12 1.1904271    F-test  0.4726027 0.513917579 1  TRUE
#> 13 0.6728081    F-test  0.4726027 0.513917579 1  TRUE
#> 14 1.7043987    F-test  0.4726027 0.513917579 1  TRUE
#> 15 1.2510298    F-test  0.4726027 0.513917579 1  TRUE
#> 16 1.6450202    F-test  0.4726027 0.513917579 1  TRUE
#> 17 1.3920961    F-test  0.4726027 0.513917579 1  TRUE
#> 18 1.3349258    F-test  0.4726027 0.513917579 1  TRUE
#> 19 1.5857889    F-test  0.4726027 0.513917579 1  TRUE
#> 20 0.7073795    F-test  0.4726027 0.513917579 1  TRUE
#> 21 1.2944484    F-test  0.1342374 0.724901776 2  TRUE
#> 22 1.1904271    F-test  0.1342374 0.724901776 2  TRUE
#> 23 0.6728081    F-test  0.1342374 0.724901776 2  TRUE
#> 24 1.7043987    F-test  0.1342374 0.724901776 2  TRUE
#> 25 1.2510298    F-test  0.1342374 0.724901776 2  TRUE
#> 26 1.6450202    F-test  0.1342374 0.724901776 2  TRUE
#> 27 1.3920961    F-test  0.1342374 0.724901776 2  TRUE
#> 28 1.3349258    F-test  0.1342374 0.724901776 2  TRUE
#> 29 1.5857889    F-test  0.1342374 0.724901776 2  TRUE
#> 30 0.7073795    F-test  0.1342374 0.724901776 2  TRUE

# Plot the lineup
test$plot_lineup(test$gen_lineup(100))


test <- poly_model(shape = 1, include_z = FALSE, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))


test <- poly_model(shape = 2, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))


test <- poly_model(shape = 3, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))


test <- poly_model(shape = 4, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))