A utility function for producing random regressors with a specified number of degrees of freedom.
Usage
rand(df = 1, rdist = rnorm, args = list(), nrow, seed = NULL)Arguments
- df
degrees of freedom, i.e., number of random regressors
- rdist
random distribution function for sampling
- args
arguments for
rdist- nrow
number of rows in resulting matrix. This can often be omitted in the context of functions like
lmwhere it is inferred from the data frame, if one is provided.- seed
seed for random number generation
Value
A matrix of random variates with df columns.
In its intended use, the number of rows will be selected to match the
size of the data frame supplied to lm
Examples
rand(2,nrow=4)
#> [,1] [,2]
#> [1,] -0.2578632 0.4079083
#> [2,] -0.4581839 0.5132579
#> [3,] 0.2708438 0.2311685
#> [4,] -2.8662993 -2.3355036
rand(2,rdist=rpois, args=list(lambda=3), nrow=4)
#> [,1] [,2]
#> [1,] 3 4
#> [2,] 4 1
#> [3,] 8 5
#> [4,] 1 0
summary(lm( waiting ~ eruptions + rand(1), faithful))
#>
#> Call:
#> lm(formula = waiting ~ eruptions + rand(1), data = faithful)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -12.0387 -4.4633 0.2022 3.9211 15.9570
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 33.49280 1.16340 28.789 <2e-16 ***
#> eruptions 10.72505 0.31680 33.855 <2e-16 ***
#> rand(1) -0.05678 0.37683 -0.151 0.88
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Residual standard error: 5.925 on 269 degrees of freedom
#> Multiple R-squared: 0.8115, Adjusted R-squared: 0.8101
#> F-statistic: 578.9 on 2 and 269 DF, p-value: < 2.2e-16
#>