Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extractor functions for simcf #31

Open
chrisadolph opened this issue Apr 2, 2012 · 1 comment
Open

Extractor functions for simcf #31

chrisadolph opened this issue Apr 2, 2012 · 1 comment
Labels

Comments

@chrisadolph
Copy link
Owner

In tandem with adding simulation results to cf objects, we need to write extractor functions to pull out point estimates, lower bounds, and upper bounds.

I'm open to suggestions as to what to call these functions. pe() should work for point estimates; lower() and upper() would be nice, but maybe they conflict with a popular package? If not, we could have very simple names.

The only required input would be the cf object, and so

pe(yhyp)

should return all the point estimates in the cf object yhyp.

But you could specify subsets, so

pe(yhyp, scen=5:10, cat=2, period=1:10, eq=1)

would indicate scenarios 5 to 10 in the second category of a categorical outcome variable, and only in periods 5 to 10 of forecasts into the future, and only in the second equation of a multi-equation model. (Obviously not all of these arguments will apply in a specific case; and eq is there for future compatibility.) lower() and upper() also will have a ci argument.

The extractors will look in the cf object to learn the dimensions of the it's simulations, then return the requested segments in whatever format (vector, matrix, array). The cf argument will also provide information of what levels each confidence interval corresponds to.

These extractor functions can be used by end users, but also by tile traces when they encounter a cf object.

@aserlich
Copy link
Collaborator

Hi,

So this is some preliminary code for the extractor model. One thing we need to answer for lower and upper is whether people need to have already simulated the confidence intervals or with the new counterfactual object, we can go and redo this for them on the fly.

cfpe <- function(cf, scen=NULL, cat=NULL, period=NULL, eq=NULL) {
    #if (cf$cfMake.call[["eqtype"]]) %in% c("simple")) {
        if (is.vector(cf[["pe"]])) cf[["pe"]] <- as.matrix(cf[["pe"]])
        #dim doesn't work on vectors. Should make this a matrix please
        peDim <- dim(cf[["pe"]])
        if(is.null(scen))  assign("scen", seq(1, peDim[1]))
        if(is.null(cat))  assign("cat", seq(1, peDim[2]))
        pe.out <- cf[["pe"]][scen, cat] #we can go an recalculate from original simulates or not
    #}  
    return(pe.out)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants