Two-dimensional Monte Carlo: Difference between revisions
Jump to navigation
Jump to search
(comment about marginals) |
(→Rationale: updated to enable additional indices using info ovariable) |
||
Line 24: | Line 24: | ||
== Rationale == | == Rationale == | ||
<rcode name="mc2d"> | <rcode name="mc2d" embed=1> | ||
#This is code Op_en7805/mc2d on page [[Two-dimensional Monte Carlo]] | #This is code Op_en7805/mc2d on page [[Two-dimensional Monte Carlo]] | ||
library(OpasnetUtils) | library(OpasnetUtils) | ||
Line 45: | Line 45: | ||
N2 = 1000, # Number of iterations in the new Iter | N2 = 1000, # Number of iterations in the new Iter | ||
run2d = TRUE, # Should the mc2d function be used or not? | run2d = TRUE, # Should the mc2d function be used or not? | ||
info = 1, # Ovariable that contains additional indices, e.g. newmarginals. If none, use 1. | |||
newmarginals = c("Gender", "Ages", "Country"), # Names of columns that are non-marginals but should be sampled enough to become marginals | newmarginals = c("Gender", "Ages", "Country"), # Names of columns that are non-marginals but should be sampled enough to become marginals | ||
method = "bootstrap", # which method to use for 2D Monte Carlo? Currently bootsrap is the only option. | method = "bootstrap", # which method to use for 2D Monte Carlo? Currently bootsrap is the only option. | ||
Line 52: | Line 53: | ||
mc2d <- function(ova) { | mc2d <- function(ova) { | ||
if(!exists("mc2dparam")) stop("Parameter list mc2dparam missing!\n") | if(!exists("mc2dparam")) stop("Parameter list mc2dparam missing!\n") | ||
ova <- ova * mc2dparam$info | |||
require(reshape2) | require(reshape2) | ||
marg <- setdiff(c(colnames(ova@output)[ova@marginal], mc2dparam$newmarginals), "Iter") | marg <- setdiff(c(colnames(ova@output)[ova@marginal], mc2dparam$newmarginals), "Iter") |
Revision as of 12:41, 4 October 2017
Moderator:Jouni (see all) |
|
Upload data
|
Question
How to perform two-dimensional Monte Carlo in Opasnet?
Answer
Use function mc2d to perform two-dimensional Monte Carlo. The function samples the current ovariable results by bootstrapping, applies an aggregate function to the samples, and then produces a new Iter index location for each sample. The function requires a parameter list mc2dparam, which contains the following parameters (with some example values):
- N2 = 1000, # Number of iterations in the new Iter
- run2d = TRUE, # Should the mc2d function be used or not?
- newmarginals = c("Gender", "Ages", "Country"), # Names of columns that are non-marginals but will be sampled enough to become marginals ⇤--#: . The function will produce an ovariable that correctly has these indices as marginals. However, if the function is used within an ovariable formula (which is typically the case), the marginal status is in the end inherited from parents and they are re-converted to non-marginals. This should be fixed somehow. --Jouni (talk) 15:11, 11 June 2017 (UTC) (type: truth; paradigms: science: attack)
- method = "bootstrap", # which method to use for 2D Monte Carlo? Currently bootsrap is the only option.
- fun = mean # Function for aggregating the first Iter dimension.
You can call the function by using code
objects.latest("Op_en7805", code_name = "mc2d")
Rationale
See also
- This method is used by e.g. Health impact assessment