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 AR1_MODEL$formula, the null formula is defined in AR1_MODEL$null_formula, the alternative is defined in AR1_MODEL$alt_formula.

Arguments

phi

Numeric. The parameter for the AR(1) term. Default is phi = 0.5.

sigma

Positive numeric. Default is sigma = 1.

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 <- ar1_model(phi = 0.9, x = x, e = e)

test
#> 
#> ── <AR1_MODEL object>
#> y = ar1(1 + x + e, phi)
#>  - x: <RAND_UNIFORM object>
#>    [a: 0, b: 1]
#>  - e: <RAND_NORMAL object>
#>    [mu: 0, sigma: 0.5]
#> Parameters:
#>  - phi: 0.9
#>  - sigma: 1 

# Generate data
test$gen(10)
#>             y          x           e     .resid  .fitted
#> 1   0.9515714 0.01900064 -0.06742919 -2.3450383 3.296610
#> 2   1.5320467 0.10367271 -0.42804027 -2.2749914 3.807038
#> 3   3.1601084 0.64518137  0.13608499 -3.9113047 7.071413
#> 4   4.0636998 0.25642605 -0.03682387 -0.6641808 4.727881
#> 5   5.4010314 0.33007560  0.41362599  0.2291694 5.171862
#> 6   6.1758538 0.35774475 -0.04281922  0.8371939 5.338660
#> 7   6.7367907 0.62049175 -0.44196939 -0.1857860 6.922577
#> 8   8.6023001 0.83620571  0.70298273  0.3793355 8.222965
#> 9   9.1609523 0.10560614  0.31327610  5.3422589 3.818693
#> 10 10.0362274 0.70680258  0.08456777  2.5933434 7.442884

# Generate lineup
test$gen_lineup(10, k = 3)
#> Error in match.arg(type): 'arg' should be one of “Box-Pierce”, “Ljung-Box”

# Plot the lineup
test$plot_lineup(test$gen_lineup(100))
#> Error in match.arg(type): 'arg' should be one of “Box-Pierce”, “Ljung-Box”

test <- ar1_model(phi = 0.1, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))
#> Error in match.arg(type): 'arg' should be one of “Box-Pierce”, “Ljung-Box”

test <- ar1_model(phi = 0.3, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))
#> Error in match.arg(type): 'arg' should be one of “Box-Pierce”, “Ljung-Box”

test <- ar1_model(phi = 0.5, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))
#> Error in match.arg(type): 'arg' should be one of “Box-Pierce”, “Ljung-Box”

test <- ar1_model(phi = 0.7, x = x, e = e)
test$plot_lineup(test$gen_lineup(100))
#> Error in match.arg(type): 'arg' should be one of “Box-Pierce”, “Ljung-Box”