Difference between revisions of "OpasnetUtils/CheckMarginals"
From Testiwiki
(Observation column names are now variable specific) |
(→Code: new version) |
||
Line 14: | Line 14: | ||
# CheckMarginals ############# Assumes that all depended upon variables are in memory, as should be the case. | # CheckMarginals ############# Assumes that all depended upon variables are in memory, as should be the case. | ||
################## | ################## | ||
− | # Returns a marginal devised from the data and upstream variable marginals. | + | # Returns an ovariable with a marginal devised from the data and upstream variable marginals. |
# Marginal values for data should be stored into the database somehow | # Marginal values for data should be stored into the database somehow | ||
CheckMarginals <- function(variable) { | CheckMarginals <- function(variable) { | ||
varmar <- colnames(variable@data)[ | varmar <- colnames(variable@data)[ | ||
− | |||
!grepl(paste("^", variable@name, ":", sep=""), colnames(variable@data))& | !grepl(paste("^", variable@name, ":", sep=""), colnames(variable@data))& | ||
!colnames(variable@data) %in% c("Result", "Unit") | !colnames(variable@data) %in% c("Result", "Unit") | ||
Line 26: | Line 25: | ||
varmar <- c(varmar, paste(variable@name, "Source", sep = "_")) # Source is usually added | varmar <- c(varmar, paste(variable@name, "Source", sep = "_")) # Source is usually added | ||
# by EvalOutput so it should be in the initial list by default. | # by EvalOutput so it should be in the initial list by default. | ||
− | + | novarmar <- colnames(variable@data)[!colnames(variable@data) %in% varmar] | |
− | for (i in variable@dependencies$Name){ | + | for (i in as.character(variable@dependencies$Name)){ |
varmar <- unique(varmar, colnames(get(i)@output)[get(i)@marginal]) | varmar <- unique(varmar, colnames(get(i)@output)[get(i)@marginal]) | ||
novarmar <- unique(novarmar, colnames(get(i)@output)[!get(i)@marginal]) | novarmar <- unique(novarmar, colnames(get(i)@output)[!get(i)@marginal]) | ||
} | } | ||
varmar <- varmar[!varmar %in% novarmar] | varmar <- varmar[!varmar %in% novarmar] | ||
− | + | variable@marginal <- colnames(variable@output) %in% varmar | |
+ | return(variable) | ||
} | } | ||
</rcode> | </rcode> |
Revision as of 13:18, 26 June 2012
This page is a method.
The page identifier is Op_en5756 |
---|
Moderator:Nobody (see all) Click here to sign up. |
This page is a stub. You may improve it into a full page, and then a rating bar will appear here. |
Upload data
|
Description
Checks ovariable marginals based on its data and dependencies. Takes all columns designated as marginal as a set and then excludes all columns designated as non-marginal from that set. Returns a corrected marginal as a logical vector.
Code
# CheckMarginals ############# Assumes that all depended upon variables are in memory, as should be the case. ################## # Returns an ovariable with a marginal devised from the data and upstream variable marginals. # Marginal values for data should be stored into the database somehow CheckMarginals <- function(variable) { varmar <- colnames(variable@data)[ !grepl(paste("^", variable@name, ":", sep=""), colnames(variable@data))& !colnames(variable@data) %in% c("Result", "Unit") ] # all locs under observation/parameter index should be excluded varmar <- c(varmar, paste(variable@name, "Source", sep = "_")) # Source is usually added # by EvalOutput so it should be in the initial list by default. novarmar <- colnames(variable@data)[!colnames(variable@data) %in% varmar] for (i in as.character(variable@dependencies$Name)){ varmar <- unique(varmar, colnames(get(i)@output)[get(i)@marginal]) novarmar <- unique(novarmar, colnames(get(i)@output)[!get(i)@marginal]) } varmar <- varmar[!varmar %in% novarmar] variable@marginal <- colnames(variable@output) %in% varmar return(variable) } |