Difference between revisions of "Two-dimensional Monte Carlo"
From Testiwiki
(first draft) |
(comment about marginals) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Modelling]] | ||
+ | [[Category:R tools]] | ||
{{method|moderator=Jouni}} | {{method|moderator=Jouni}} | ||
Line 6: | Line 8: | ||
== Answer == | == 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 {{attack|# |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.|--[[User:Jouni|Jouni]] ([[User talk:Jouni|talk]]) 15:11, 11 June 2017 (UTC)}} | ||
+ | * 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 == | == Rationale == | ||
<rcode name="mc2d"> | <rcode name="mc2d"> | ||
− | #This is code | + | #This is code Op_en7805/mc2d on page [[Two-dimensional Monte Carlo]] |
library(OpasnetUtils) | library(OpasnetUtils) | ||
Line 24: | Line 39: | ||
# Boostrap-versio: | # Boostrap-versio: | ||
+ | |||
+ | # Paramter list. Note: this is not stored, you have to define it in the model code. | ||
mc2dparam<- list( | mc2dparam<- list( | ||
− | N2 = 1000, | + | N2 = 1000, # Number of iterations in the new Iter |
− | run2d = TRUE, | + | run2d = TRUE, # Should the mc2d function be used or not? |
− | newmarginals = c("Gender", "Ages", "Country"), | + | newmarginals = c("Gender", "Ages", "Country"), # Names of columns that are non-marginals but should be sampled enough to become marginals |
− | method = "bootstrap", | + | method = "bootstrap", # which method to use for 2D Monte Carlo? Currently bootsrap is the only option. |
− | fun = mean | + | fun = mean # Function for aggregating the first Iter dimension. |
) | ) | ||
Line 63: | Line 80: | ||
} | } | ||
− | objects. | + | objects.store(mc2d) |
cat("Function mc2d stored.\n") | cat("Function mc2d stored.\n") | ||
</rcode> | </rcode> |
Latest revision as of 15:11, 11 June 2017
This page is a method.
The page identifier is Op_en7805 |
---|
Moderator:Jouni (see all) |
Give your opinion to the peer rating of the content of this page. |
Upload data
|
Contents
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)
- 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