简体   繁体   中英

Trying to store estimates when using "replicate" in R

I am new to RStudio and have a question I was hoping one could help me with. I am using the "replicate" function to simulate a log-GARCH model, what I get is 100 replications and what I want to do is store the estimates such that I can calculate the average. How can I do that?

Code:

library(lgarch)


replicate(n=100,{ x <- lgarchSim(500, constant=0.5) mymod <- lgarch(x) }, simplify=FALSE )

This produced the following output:

Output

Attached is an image of replication [99] and [100], what I essentially want is to store "intercept" "arch1" and "garch1" in a list.

The result is giving you a list of models. You can use lapply to extract the coefficients from each model, rbind them together into a matrix and get the colMeans to get your averages coefficients:

library(lgarch)

my_list <- replicate(n = 100, { 
  x <- lgarchSim(500, constant = 0.5)
  mymod <- lgarch(x) 
  }, simplify = FALSE )

colMeans(do.call(rbind, lapply(my_list, coefficients)))
#>   intercept       arch1      garch1       Elnz2 
#>  1.15879953  0.04965793  0.82525587 -1.26277188 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM