Training assessment/Decisions: Difference between revisions

From Opasnet
Jump to navigation Jump to search
(→‎Answer: doesn't work yet)
(redirected)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{variable|moderator=Jouni}}
#REDIRECT [[Training assessment]]
[[Category:Open assessment]]
[[Category:Training]]
'''Training decision''' describes decision options for an imaginary assessment designed for training.
 
==Question==
 
What are plausible policies for the [[Training assessment]]?
 
==Answer==
 
<t2b index="Decision,Option,Variable,Cell,Change,Observation" locations="Unit,Amount,Description" unit="-">
Exposure policy|Reduce exposure|Training exposure|Year: 2012|Multiply|-|0.5|
Health promotion|Reduce background risk|Training health impact||Multiply|-|0.9|
Health promotion|Promotion budget reduced|Training health impact||Multiply|-|1.1|
</t2b>
 
<rcode
name="answer"
label="Run code"
graphics="1"
include="
page:Opasnet_(R_library)|    name:answer|
page:Training_exposure|      name:formula|
page:Training_health_impact| name:formula
"
variables="
name:population|description:What is the size of population?|default:100000
"
>
 
# APPLY.DECISIONS ############## apply.decisions takes a decision table and applies that to an assessment.
## dec is a decision data.frame that must have columns Decision, Option, Variable, Cell, Change, Result. It can have several variables.
apply.decisions <- function(assessment) {
dec <- merge(assessment@decisions, assessment@dependencies, by.x = "Variable", by.y = "Name")
colnames(dec)[colnames(dec) == "Result.x"] <- "Result"
colnames(dec)[colnames(dec) == "Result.y"] <- "Name"
print(xtable(dec), type = 'html')
# out <- as.list(unique(dec$Name))
# names(out) <- as.character(unique(dec$Name))
 
for(variables in unique(dec$Name)) { # Take one variable at a time.
dec.var <- dec[dec$Name == variables, ] # dec.var = variable-specific decisions
print(xtable(dec.var), type = 'html')
scenarios <- data.frame(temp = 1)
 
for(decisions in unique(dec.var$Decision)) { # Add BAU option to each decision and merge decisions.
temp <- as.character(dec.var[dec.var$Decision == decisions, "Option"])
temp <- data.frame(Options = c(temp, "BAU"))
colnames(temp) <- decisions
scenarios <- merge(scenarios, temp)
}
print(scenarios)
var <- assessment@vars[[as.character(dec.var$Name[1])]]
var <- merge(scenarios[colnames(scenarios) != "temp"], var)
print(var)
for(s in 1:nrow(dec.var)) { # Each row in decision handled separately
cell <- gsub("^[ \t]+|[ \t]+$", "", as.character(dec$Cell[s])) # Leading and trailing whitespaces removed.
cell <- gsub(":[ \t]+", ":", cell) # Whitespaces removed after :
cell <- gsub(";[ \t]+", ";", cell) # Whitespaces removed after ;
cell <- gsub("[ \t]+:", ":", cell) # Whitespaces removed before :
cell <- gsub("[ \t]+;", ";", cell) # Whitespaces removed before ;
cell <- strsplit(cell, split = ";") # Separate cell identifiers (indices and locations)
cell <- strsplit(cell[[1]], split = ":")
cond <- as.character(dec.var$Decision[s])
cond <- var[, cond] == as.character(dec.var$Option[s]) # Only the rows with the relevant option.
for(r in 1:length(cell)) { # All Cell conditions extracted and combined with AND.
cond <- cond * (var[, cell[[r]][1]] == cell[[r]][2])
}
cond <- as.logical(cond)
if(dec.var$Change[s] == "Replace" ) {var[cond, "Result"] <- dec.var$Result[s]}
if(dec.var$Change[s] == "Add"    ) {var[cond, "Result"] <- dec.var$Result[s] + var[cond, "Result"]}
if(dec.var$Change[s] == "Multiply") {var[cond, "Result"] <- dec.var$Result[s] * var[cond, "Result"]}
}
 
assessment@vars[[variables]] <- var
}
return(assessment)
}
 
cat("Initiation complete. Now starting the model.\n")
 
assessment.training <- make.oassessment("Op_en5677")
 
assessment.training <- apply.decisions(assessment.training)
 
</rcode>
 
==Rationale==
 
 
==See also==
 
{{Opasnet training}}
 
==References==
 
<references/>
 
==Related files==
 
{{mfiles}}

Latest revision as of 19:21, 30 December 2012