Difference between revisions of "User:Mori"

Tuukka Hämynen, A.K.A. Mori

THL

Kooditestausta

<section begin=glossary />
Decision is a special kind of variable: it answer a question like this: "What are different decisions that decision maker X can make in situation Y, and what are different options of each decision?" Decision maker X may be a single individual, a decision making body with several individuals, or a set of separate decision makers, who each can decide about some but not all decisions. In such a situation, an especially interesting part of the related assessment is to look at the interactions of the decisions by different decision makers, none of which can fully control the decision situation.
The decisions have a special role in causal diagrams, as they list such specific structural parts of variables in a causal diagrams that can be modified by a decision maker. Without a decision, the causal diagram describes the business-as-usual (BAU) situation. A decision variable describes how the situation changes if a decision maker chooses an option over another options of a decision.

<section end=glossary />

Question

How should decisions be described in open assessment and what should their structure be?

A typical structure of a data table of a decision.
Decision maker Decision Option Variable Cell Change ... Value Description
The person or group who can decide about this. Typically, one of the stakeholder groups. A group of options that are exclusive and the choice between them is made by one decision making body. An option within one decision. A variable whose value is to be changed by the decision option. A cell whose value is to be changed within the variable data table. The type of change. Possible options:
• Add the value to the existing value.
• Multiply the value with the existing value.
• Replace the existing value with this value.
• Remove those rows from the variable that fulfil the cell criterion.
• Insert rows to the variable based on data in the decision.
• Split the existing random sample into two parts from the value. This is especially needed in upstream inference.
The table may also contain other indices. The functions dealing with decision variables use the default merge functionality when combining objects. The value to be used in the calculations. This row contains descriptions about columns. The next rows contain examples.
City of Kuopio Energy saving education Training to house owners Energy balance in Kuopio Activity: Residential; Fuel: Heat Multiply 0.94 Energy training leads to renovation of houses and leads to heating demand reduction by 6 %.
City of Kuopio Public transport subsidy More money to bus transport Energy balance in Kuopio Activity: Transport; Fuel: Petrochemical products Multiply 0.95 Energy consumption of buses increases diesel use by 2.5 % but the reduced car transport causes a net reduction of 5 % in fuel use.
City of Kuopio Public transport subsidy Much more money to bus transport Energy balance in Kuopio Activity: Transport; Fuel: Petrochemical products Multiply 0.9 Energy consumption of buses increases diesel use by 5 % but the reduced car transport causes a net reduction of 10 % in fuel use.

Rcode

 ``` ############### decisions.applyx 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. decisions.applyx <- function(dec, assessment = NULL) { out <- as.list(unique(dec\$Variable)) names(out) <- as.character(unique(dec\$Variable)) for(variables in unique(dec\$Variable)) { # Take one variable at a time. dec.var <- dec[dec\$Variable == variables, ] # dec.var = variable-specific decisions 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) } if(!is.null(assessment)) { var <- assessment@vars[[as.character(dec.var\$Variable[1])]] } else { if(exists(as.character(dec.var\$Variable[1]))) {var <- get(as.character(dec.var\$Variable[1])) } else { stop() } } var <- merge(scenarios[colnames(scenarios) != "temp"], 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"]} } out[[variables]] <- var } return(out) } ```

Test code

 ```library(xtable) var1 <- data.frame(c = c("A", "A", "C"), d = c("D", "E", "E"), Result = 4:6) var2 <- var1 dec <- data.frame(Decision = rep(c("Decision 1", "Decision 2"), each = 2), Option = c("OptA", "OptB"), Variable = c("var1", "var1", "var1", "var2"), Cell = c(" c: A; d: E", " d: D"), Change = c("Replace", "Multiply"), Result = 7:10) var1 dec out <- decisions.applyx(dec) cat("Variable", names(out)[1], "\n") print(xtable(out[[1]]), type = 'html') cat("Variable", names(out)[2], "\n") print(xtable(out[[2]]), type = 'html') library(OpasnetUtils) data <- tidy(op_baseGetData("opasnet_base", "Op_en5466"), direction = "wide") data <- data[colnames(data) != "Unit"] data data <- decisions.applyx(data) ```

⇤--#: . Why does the var2 outcome show row 3 OptB A E 50, because the decision should be applied only for row 1 OptB A D 4 ? There is a bug somewhere. --Jouni 16:12, 16 May 2012 (EEST) (type: truth; paradigms: science: attack)

TODO: {{#todo:Tässä kommentissa on toinen R-koodaukseen liittyvä työ. Samalla pääset opiskelemaan koodin käyttöä, kun etsit virhettä koodista. --Jouni 17:21, 22 June 2012 (EEST)|Tuukka Hämynen|}}

Rationale

Previously, it was thought that decision variables are an essential starting point of a causal diagram, and that they should be general and applicable to all possible situations where that causal diagram is used. Now the thinking is different. Decisions are seen as descriptions of plausible options decision makers have in a particular situation. Decisions are implemented in an assessment as scenarios (deliberate deviations from the truth, asking: "What would happen if the truth about the decision maker's action was this?"). It was previously also thought that decisions are probability distributions about what a decision maker will decide, and assessment-specific scenarios are used separately to select the interesting options from the decision distribution in a particular assessment. Now the thinking is different: instead of attempting to describe all the decisions explicitly, the core of a causal diagram does not describe any decisions. It just describes the phenomena that are important for understanding a situation, such as activities, emissions, exposures, and health effects. Decisions that may change the future situation are implicitly included in the probability distributions as uncertainties. Then, decisions are added to that for describing how e.g. activities would change if some decision options would be chosen. Mathematically, this means that one or more variables in a model are conditionalised to reflect the impact of decisions. In other words, decision variables are used as scenarios. What are scenarios, anyway?

A scenario is a deliberate deviation from the truth in a description. In the case of decisions, it is a particular value of some variable that is changed if the decision option at hand is implemented. It can also be a set of particular values of several variables changed by the decision. For policy assessments, often several scenarios are defined and then compared to each other, e.g. if the impacts of a certain policy (measure) is assessed. A particular set of scenarios can be saved and used in several risk assessments. A scenario therefore can be a part of an assessment but is not an assessment itself. In a sense, BAU is not a scenario, it is our best estimate about what will actually happen, implicitly including all plausible decisions by all decision makers.

A decision describes changes in values of other variables. These changes must be within the range of values the variable has.R↻