[R] Not the same length
David Winsemius
dw|n@em|u@ @end|ng |rom comc@@t@net
Tue Sep 17 23:13:19 CEST 2019
On 9/17/19 2:08 PM, David Winsemius wrote:
>
> On 9/17/19 1:35 PM, varin sacha wrote:
>> Many thanks David, it perfectly works.
>> Now, one last think.
>> If I want my R code here below to run let's say B=500 times and at
>> the end I want to get the average for the MSE_GAM and for the
>> MSE_MARS. How can I do that ?
>
>
> The `replicate` function is designed for that purpose.
Although I also just noticed that you were separately computing
residuals. Many R regression functions return a residual vector. Your
code would be a lot faster over the course of 500 repeats if you used
the resid function:
> str( resid(gam_model))
num [1:2000] -0.1385 0.1848 -0.0567 0.0605 -0.3297 ...
> str( resid(mars_model))
num [1:2000, 1] -0.2181 0.294 -0.0773 0.1626 -0.3512 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:2000] "1" "2" "3" "4" ...
..$ : chr "y_obs"
More information about the R-help
mailing list