Description Usage Arguments Examples

View source: R/importance_sample.R

Returns `nsim`

samples from the approximating Gaussian model with corresponding
(scaled) importance weights. Probably mostly useful for comparing KFAS and bssm packages.

1 2 3 4 5 6 7 8 9 10 11 12 | ```
importance_sample(model, nsim, use_antithetic, max_iter, conv_tol, seed, ...)
## S3 method for class 'nongaussian'
importance_sample(
model,
nsim,
use_antithetic = TRUE,
max_iter = 100,
conv_tol = 1e-08,
seed = sample(.Machine$integer.max, size = 1),
...
)
``` |

`model` |
of class |

`nsim` |
Number of samples. |

`use_antithetic` |
Logical. If |

`max_iter` |
Maximum number of iterations used for the approximation. |

`conv_tol` |
Convergence threshold for the approximation. Approximation is
claimed to be converged when the mean squared difference of the modes is
less than |

`seed` |
Seed for the random number generator. |

`...` |
Ignored. |

1 2 3 4 5 6 7 8 9 10 11 12 13 | ```
data("sexratio", package = "KFAS")
model <- bsm_ng(sexratio[, "Male"], sd_level = 0.001, u = sexratio[, "Total"],
distribution = "binomial")
imp <- importance_sample(model, nsim = 1000)
est <- matrix(NA, 3, nrow(sexratio))
for(i in 1:ncol(est)) {
est[, i] <- Hmisc::wtd.quantile(exp(imp$alpha[i, 1, ]), imp$weights,
prob = c(0.05,0.5,0.95), normwt=TRUE)
}
ts.plot(t(est),lty = c(2,1,2))
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.