Training assessment: Difference between revisions

From Opasnet
Jump to navigation Jump to search
(→‎Rationale: No additional " " allowed in decision tables.)
Line 89: Line 89:
library(xtable)
library(xtable)
library(ggplot2)
library(ggplot2)
###########################333
######################
# CheckDecisions
#####################
# Function that checks for and applies decisions for a variable if such exist.
# Inputs:
#  * variable - ovariable to be checked
#
# For the function to actually do anything, an odecision variable that matches the name DecVariable (where "Variable" is the
# name of the variable of interest) has to be defined before running CheckDecisions. Odecision class definition can be found
# below. The function also makes use of a preset of decision effects which match a given string constant (i.e. "Multiply").
#######################
CheckDecisions <- function(variable) {
if(exists(paste("Dec", variable@name, sep = ""))) {
# Initialization: Setting up a data.frame upon which to apply desired decision - option specific effect.
dec <- get(paste("Dec", variable@name, sep = "")) # Get decision variable
dectable <- dec@dectable # Decision input table in format described on http://en.opasnet.org/w/Decision
temp2 <- data.frame(ignoremeiamadummy = NA) # A mergeable dummy for loop initial value
for (i in unique(as.character(dectable$Decision))) { # Decisions form new indices. Here the decision indices are merged together.
tempdec <- dectable$Option[dectable$Decision == i]
temp2 <- merge(temp2, tempdec)
}
temp2 <- temp2[!colnames(temp2) %in% "ignoremeiamadummy"] # remove dummy column
out <- merge(variable@output, temp2) # Merge decisions with output.
# Conditions: Constructing a list of logical vectors which correspond to those rows of our new data.frame that we want to apply
# effects on. This will be done either by the user (as functions that take the data.frame as input and return a logical vector)
# while defining a custom decision or by parsing the decision table.
cond <- list()
# First check if condition functions have been given. The default for the condition slot of an ovariable is a function that returns 0.
if (length(dec@condition) == 1 & dec@condition[[1]](variable@output) == 0) {
# Build multiple condition vectors that correspond to a unique decision - option combination
for (j in 1:nrow(dectable)) {
# In the decision table format conditions are given in the "Cell"-column separated by ";".
sel1 <- strsplit(dectable[j, "Cell"], split = ";")[[1]]
# ":" defines index - location matches as a condition.
sel2 <- strsplit(sel1, split = ":") # No need for lapply, since strsplit is a vectorized function and current list depth is 1.
# Create a list of conditions which the decision and option specific condition vector consists of.
selection <- list()
for (k in 1:length(sel1)) { # For each condition separated by ";"
if (length(sel2[[k]]) > 1) { # If ":" has been used for condition k
locs <- strsplit(sel2[[k]][2], split = ",") # Split by "," for multiple locs per given index
selection[[k]] <- out[, sel2[[k]][1]] %in% locs # Match our data.frame to the condition
} #else { # Unimplemented code for (in)equality checks for numeric variables
#if(grepl(">=")) {
#a <- strsplit(sel1[[k]])
#b <-  <- out[, sel2[[k]][1]]
#selection[[k]]
#}
#}
}
# Match all conditions given for this decision - option combination.
selection <- as.data.frame(selection)
selection$optslice <- out[[as.character(dec[j,1])]] == dec[j,2] # We only want rows where the relevant option is in use to be affected
selection <- as.matrix(selection)
cond[[j]] <- apply(
selection,
1,
all
)
}
} else { # Otherwise use given condition functions.
for (j in 1:length(dec@condition)) {
cond[[j]] <- dec@condition[[j]](variable@output)
}
}
# Effects
if (length(dec@effect) == 1 & dec@effect[[1]](variable@output) == 0) {
eff <- list()
for (j in 1:nrow(dectable)) {
eff[[j]] <- EffectPreset(dectable$Change) # Returns a standard function from presets defined below.
}
} else {
eff <- dec@effect
}
# Applying effects
for (j in 1:nrow(dectable)) {
out[
cond[[j]],
paste(variable@name, "Result", split = "")
] <- eff[[j]](
out[
cond[[j]],
paste(variable@name, "Result", split = "")
],
dectable$Value[j]
)
}
variable@marginal <- colnames(out) %in% c(colnames(variable@output)[variable@marginal], colnames(temp2))
variable@output <- out
}
return(variable)
}
#########################


net.cost <- new("ovariable",
net.cost <- new("ovariable",
Line 230: Line 111:
)
)


DecisionTableParser <- function(DTable){ # DTable is a data.frame
decisions <- opbase.data("Op_en5677.decisions")
for (i in unique(as.character(DTable$Variable))) {
temp <- DTable[DTable$Variable == i,] # c("Decision", "Option")]
out <- new("odecision", dectable = temp)
assign(paste("Dec", i, sep = ""), out, envir = .GlobalEnv)
}
}
 
decisions <- tidy(opbase.data("Op_en5677.decisions"), objname = "decisions")
DecisionTableParser(decisions)
DecisionTableParser(decisions)


Fetch2(data.frame(Name = "health.impact", Key = "iaTGnY1hgUP5tofT"))
Fetch2(data.frame(Name = "health.impact", Key = "iaTGnY1hgUP5tofT"))


CheckDecisions(health.impact)
health.impact <- EvalOutput(health.impact)
health.impact <- CheckDecisions(health.impact)
colnames(health.impact@output)
 
print(xtable(health.impact@output[1:20,]), type = "html")


probabilities <- new("ovariable",
probabilities <- new("ovariable",
Line 250: Line 127:
)
)


summary(endpoints)
#summary(endpoints)
decisions
#decisions
summary(probabilities)
#summary(probabilities)


</rcode>
</rcode>

Revision as of 12:53, 31 December 2012



This is a training assessment about an imaginary, simple case. The purpose is to illustrate assessment functionalities.

Scope

Question

What decisions are worth implementing in the training assessment?

Boundaries

  • Time: Year 2012 - 2020

Scenarios

  • Factory can reduce emissions, or continue business as usual.
  • School can increase health education, decrease it to save money, or continue business as usual.

Intended users

  • Anyone who wants to learn to make open assessments.

Participants

  • Main participants:
    • YMAL,
    • Summer workers of YMAL in 2012,
    • Participants of [[Decision analysis and risk management 2013}}

Answer

Conclusions

Results

Not yet available.

Rationale

The causal diagram for the training assessment.

Assessment-specific data

Decisions
Decisions(-)
ObsDecisionmakerDecisionOptionVariableCellChangeUnitAmountDescription
1FactoryCleaning.policyReduce emissionsexposureYear:2020Multiply-0.5
2SchoolHealth.promotionIncrease health educationhealth.impactYear:2020Multiply-0.9
3SchoolHealth.promotionPromotion budget reducedhealth.impactYear:2020Multiply-1.1
Probabilities
Probabilities(P)
ObsStakeholderVariableCellProbabilityDescription
1City of KuopioexposureCleaning.policy: Reduce emissions0.8
2City of KuopioexposureCleaning.policy: BAU0.2
3Factoyhealth.impactHealth.promotion: Increase health education0.1
4Factoyhealth.impactHealth.promotion: Promotion budget reduced0.4
5Factoyhealth.impactHealth.promotion: BAU0.5
Endpoints
Endpoints(-)
ObsStakeholderVariableCellModelResultDescription
1City of Kuopiohealth.impactYear:2012Weighted sum1000
2City of Kuopiohealth.impactYear:2020Weighted sum1000
3Citizenshealth.impactYear:2012Weighted sum1000
4Citizenshealth.impactYear:2020Weighted sum2000Future years are twice as important.
Variables
Analyses
  • Decision analysis on each policy: Which option minimises the health risks?
  • Value of information (VOI) analysis for each policy about the major variables in the model and the total VOI.

Calculations

+ Show code

See also

Materials and examples for training in Opasnet and open assessment
Help pages Wiki editingHow to edit wikipagesQuick reference for wiki editingDrawing graphsOpasnet policiesWatching pagesWriting formulaeWord to WikiWiki editing Advanced skills
Training assessment (examples of different objects) Training assessmentTraining exposureTraining health impactTraining costsClimate change policies and health in KuopioClimate change policies in Kuopio
Methods and concepts AssessmentVariableMethodQuestionAnswerRationaleAttributeDecisionResultObject-oriented programming in OpasnetUniversal objectStudyFormulaOpasnetBaseUtilsOpen assessmentPSSP
Terms with changed use ScopeDefinitionResultTool


  • Descriptions of a previous structure
  • ----#: . Päätöksenteon sokea piste: se mitä ihmiset eivät näe mutta eivät myöskään huomaa etteivät näe. Kuitenkin tutkimalla sitä mitä mitä ihmiset eivät näe saadaan selville asioita sokeasta pisteesta. Ymmärtämällä sokeaa pistettä voidaan keksiä asioita jotka järjestelmällisesti jäävät huomaamatta ja asioita, joilla voidaan korjata järjestelmällisiä puutteita. Avoin arviointi on tämmöinen päätöksenteon järjestelmällisten puutteiden korjausmekanismi. --Jouni 08:55, 1 May 2012 (EEST) (type: truth; paradigms: science: comment)

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>