Training assessment: Difference between revisions

From Opasnet
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 53: Line 53:
Factory|Cleaning_policy|Reduce emissions|exposure|Year:2020|Multiply|-|0.5|  
Factory|Cleaning_policy|Reduce emissions|exposure|Year:2020|Multiply|-|0.5|  
Factory|Cleaning_policy|BAU|costs||Add|€|0|  
Factory|Cleaning_policy|BAU|costs||Add|€|0|  
Factory|Cleaning_policy|Reduce emissions|costs|Year:2020;Expenditure:Cleaning equipment use|Add|€|50000|  
Factory|Cleaning_policy|Reduce emissions|costs|Year:2020;Expenditure:Cleaning equipment use|Add|€|30000-40000|  
City of Kuopio|Health_promotion|BAU|health_impact||Multiply|-|1|
City of Kuopio|Health_promotion|BAU|health_impact||Multiply|-|1|
City of Kuopio|Health_promotion|Increase health education|health_impact||Multiply|-|0.9|
City of Kuopio|Health_promotion|Increase health education|health_impact||Multiply|-|0.9|
Line 82: Line 82:


objects.latest("Op_en5675", code_name = "initiate") # [[Training health impact]] health_impact
objects.latest("Op_en5675", code_name = "initiate") # [[Training health impact]] health_impact
objects.latest("Op_en5871", code_name = "initiate") # [[Training cost]] costs
objects.latest("Op_en5871", code_name = "initiate") # [[Training costs]] costs


unitcost <- Ovariable("unitcost", data = data.frame(Result = unitcost))
unitcost <- Ovariable("unitcost", data = data.frame(Result = unitcost))


costs <- EvalOutput(costs)
costs <- CheckDecisions(EvalOutput(costs))


oprint(summary(health_impact))
costs2 <- oapply(unkeep(costs, sources = TRUE), cols ="Expenditure", FUN = sum)


ggplot(health_impact@output, aes(x = health_impactResult, colour = Year)) + geom_density() +
cat("Summary of exposures\n")
theme_gray(base_size = 24) +
facet_grid(Cleaning_policy ~ Health_promotion)


ggplot(costs@output, aes(x = costsResult, colour = Year)) + geom_density() +
oprint(summary(exposure))
theme_gray(base_size = 24) +
facet(grid(Cleaning_policy ~ Health_promotion)


</rcode>
cat("Summary of health impacts\n")


<rcode label="testcode">
oprint(summary(health_impact), digits = 0)
dectable <- data.frame(
Stakeholder = rep(c("School", "City of Kuopio"), 4),
Variable = rep(c("health.impact", "exposure"), each = 2),
Cell = c("Year:2012,2014,2020", "Year:2012"),
Result = 2
)


health.impact <- data.frame(Year = 2011:2010, Result = 1:10)
cat("Summary of all costs\n")


exposure <- data.frame(Year = 2012, Result = 100:110)
oprint(summary(costs2), digits = 0)


# temp <- tempovar@output[tempovar@output$health.impactSource == "Formula", ]
ggplot(exposure@output, aes(x = exposureResult, colour = Year)) + geom_density() +
theme_gray(base_size = 24) +
facet_grid(Cleaning_policy ~ .)


dectable <- dectable[dectable$Stakeholder == "School" & dectable$Variable == "health.impact", ]
ggplot(health_impact@output, aes(x = health_impactResult, colour = Year)) + geom_density() +
theme_gray(base_size = 24) +
facet_grid(Cleaning_policy ~ Health_promotion)


#####################
ggplot(subset(costs2@output, Year == 2020), aes(x = costsResult, colour = Payer)) + geom_density() +
##### SelectCond takes conditions and slices a data.frame leaving rows that fulfil the conditions.
theme_gray(base_size = 24) +
##### SelectCond can be used for ovariables as well, then ovariable@output is taken as the data.frame.
facet_grid(Cleaning_policy ~ Health_promotion)
##### Parameters: conditions: a data.frame with conditions for slicing. It must contain columns Variable and Cell.
###### Result and Stakeholder are optional but they are typically needed for further use.
###### Stakeholder and Variable columns must have the same values at each row,  
###### i.e. the Stakeholder-Variable pair must be unique.
###### There must exist a data.frame or ovariable with the name found in the Variable column.


SelectCond <- function(conditions, ...) {
ggplot(subset(costs2@output, Year == 2020), aes(x = Payer, weight = costsResult / openv$N, fill = Payer)) + geom_bar() +
theme_gray(base_size = 24) +
facet_grid(Cleaning_policy ~ Health_promotion)


temp <- get(as.character(dectable[1, "Variable"]))
if(class(temp) == "ovariable") {temp <- temp@output}


for (j in 1:nrow(dectable)) {
# In the decision table format conditions are given in the "Cell"-column separated by ";".
sel1 <- strsplit(as.character(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.
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 = ",")[[1]] # Split by "," for multiple locs per given index
temp <- temp[temp[, sel2[[k]][1]] %in% locs , ] # Match our data.frame to the condition
temp <- temp[, colnames(temp) != sel2[[k]][1] ] # Remove all indices that were  used in selecting rows, because otherwise they cannot be merged.
cat(j, k, "\n")
}
}
}
return(temp)
}
SelectCond(dectable)


</rcode>
</rcode>


<rcode
=== Explanations of the code ===
name="answer"
graphics="1"
include="page:OpasnetUtils/Summary|name:summary"
>
library(OpasnetUtils)
library(xtable)
library(ggplot2)
 
# List of decisions to be included in the ovariables as scenarios.
 
decisions <- tidy(opbase.data("Op_en5677.decisions"))
 
# The next row should happen inside tidy but it doesn't. Why?
decisions <- decisions[ , colnames(decisions) != "Obs"]
 
# BAU options are added to each combination Decisionmaker - Decision - Variable. This should be included in the DecisionTableParser.
BAUs <- decisions[!duplicated(decisions[c("Decisionmaker", "Decision", "Variable")]), ]
BAUs$Change <- "Add"
BAUs$Result <- 0
BAUs$Option <- "BAU"
decisions <- rbind(BAUs, decisions)
 
DecisionTableParser(decisions)
 
Fetch2(data.frame(Name = c("health.impact", "exposure", "training.costs"), Key = c("goTWH6nQtdO97JxD", "m22i7AfzxByOBaaG", "axwlfkG0w4RYJsAi")))
 
# Evaluate ovariables and add decisions to them. This part should be put inside ComputeDependencies.
 
exposure <- EvalOutput(exposure)
exposure <- CheckDecisions(exposure)
health.impact <- EvalOutput(health.impact)
health.impact <- CheckDecisions(health.impact)
training.costs <- EvalOutput(training.costs)
training.costs <- CheckDecisions(training.costs)


summary(exposure)
<pre>
summary(health.impact)
<rcode graphics=1
summary(training.costs)
variables="name:unitcost|description:What is the unit cost of one case of disease?|type:text|default:100"
>
</pre>


# Stakeholder probabilities are not implemented yet.
The tag above starts the R code. It turns on the graphics so that graphs can be drawn. It also asks the user to give a value for the variable ''unitcost''.


########### Graphs about health impacts by different decision options or source of estimates.
library(OpasnetUtils)
library(ggplot2)


ggplot(health.impact@output, aes(x = Year, y = health.impactResult, colour = Health.promotion)) +
In the beginning of a code, packages that are needed are loaded. These are the two most commonly used. OpasnetUtils is for all Opasnet functionalities, ggplot2 is for cool graphs.
geom_boxplot() +
theme_grey(base_size = 24)


ggplot(health.impact@output, aes(x = Year, y = health.impactResult, colour = Cleaning.policy)) +
DecisionTableParser(opbase.data("Op_en5677", subset = "Decisions")) # <nowiki>[[Training assessment]]</nowiki>
geom_boxplot() +
theme_grey(base_size = 24)


ggplot(health.impact@output, aes(x = Year, y = health.impactResult, colour = health.impactSource)) +
This code defines from where to take the assessment-specific decisions. In this case, they are on the page Training assessment, in a table called ''Decisions''. The page has identifier Op_en5677, which can be found from the metadata box, which is typically in the top right corner of a page.
geom_boxplot() +
theme_grey(base_size = 24)


######################### Calculate endpoints of interest for each stakeholder.
objects.latest("Op_en5675", code_name = "initiate") # <nowiki>[[Training health impact]]</nowiki> health_impact
objects.latest("Op_en5871", code_name = "initiate") # <nowiki>[[Training costs]]</nowiki> costs


endpoints <- tidy(opbase.data("Op_en5677.endpoints")) # List of stakeholders' endpoints.
These lines fetch ready-made ovariables that are needed in this assessment. The code defining these ovariables are located on the pages mentioned. Note that # is the comment character and everything after it is ignored in the model; so it is used to put explanations for the reader within the code.


# Remove these redundant columns from intermediate results:
unitcost <- Ovariable("unitcost", data = data.frame(Result = unitcost))
removals <- c("exposureUnit", "exposureDescription", "exposureSource", "health.impactDescription", "health.impactSource",
"health.impactUnit", "exposureResult", "health.impactResult")


endpoint <- list() # Initiate a list for collecting stakeholder-specific endpoints.
Unitcost was asked from the user as a value, and now it is converted to an ovariable.


for(i in unique(endpoints$Stakeholder)) {
costs <- EvalOutput(costs)
costs2 <- oapply(unkeep(costs, sources = TRUE), cols ="Expenditure", FUN = sum)


dectable <- endpoints[endpoints$Stakeholder == i, ]
Because all ovariables are connected in the model, it is enough to evaluate the last one. The model will automatically evaluate all ovariables that are causally upstream. Also, the decisions that apply to this assessment will change the results of the ovariables as necessary. Ovariable costs2 is used to summarise contents of costs for easier presentation.


# Initiate an endpoint ovariable for the next stakeholder. Results will come later.
cat("Summary of health impacts\n")
endpoint[[i]] <- new("ovariable", name = "endpoint", output = data.frame(Result = 0))


for (j in 1:nrow(dectable)) {
Function cat is used to print outputs for the user.
# In the decision table format conditions are given in the "Cell"-column separated by ";".
sel1 <- strsplit(as.character(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.
tempovar <- get(as.character(dectable[j, "Variable"]))
temp <- tempovar@output


for (k in 1:length(sel1)) { # For each condition separated by ";"
oprint(summary(health_impact), digits = 0)


if (length(sel2[[k]]) > 1) { # If ":" has been used for condition k
Function oprint is used to print tables for the user.
locs <- strsplit(sel2[[k]][2], split = ",")[[1]] # Split by "," for multiple locs per given index
temp <- temp[temp[, sel2[[k]][1]] %in% locs , ] # Match our data.frame to the condition
temp <- temp[, colnames(temp) != sel2[[k]][1] ] # Remove all indices that were  used in selecting rows, because otherwise they cannot be merged.
}
}


# Make an ovariable out of the rows matching the condition.
cat("Summary of all costs\n")
tempovar@output <- temp
oprint(summary(costs2), digits = 0)


# Multiply by the weight and add to previous stakeholder endpoint.
ggplot(exposure@output, aes(x = exposureResult, colour = Year)) + geom_density() +
theme_gray(base_size = 24) +
facet_grid(Cleaning_policy ~ .)


tempovar <- tempovar * as.numeric(as.character(dectable[j, "Result"]))
Function ggplot is very effective in creating all kinds of graphs with just a few lines. It is really worth learning.


# Remove columns that are not needed but may confuse merge.
ggplot(health_impact@output, aes(x = health_impactResult, colour = Year)) + geom_density() +
tempovar@output <- tempovar@output[ , !colnames(tempovar@output) %in% removals]
theme_gray(base_size = 24) +
endpoint[[i]] <- endpoint[[i]] + tempovar
facet_grid(Cleaning_policy ~ Health_promotion)
ggplot(subset(costs2@output, Year == 2020), aes(x = costsResult, colour = Payer)) + geom_density() +
theme_gray(base_size = 24) +
facet_grid(Cleaning_policy ~ Health_promotion)


}
<pre>
}
</rcode>
</pre>


names(endpoint)[1]
The code must always end with this tag.
summary(endpoint[[1]])
 
# names(endpoint)[2]
# summary(endpoint[[2]]) # This row causes in unidentified error even if the ovariable is OK.
 
 
 
############### Make graphs about the endpoint by decision options
 
ggplot(endpoint[[1]]@output, aes(x = Cleaning.policy, y = Result, colour = Health.promotion)) +
geom_boxplot() +
theme_grey(base_size = 24) +
labs( # label names
title = names(endpoint)[1],
y = "Euro",
x = "Cleaning policy decision"
)
 
ggplot(endpoint[[2]]@output, aes(x = Health.promotion, y = Result, colour = Cleaning.policy)) +
geom_boxplot() +
theme_grey(base_size = 24) +
labs( # label names
title = names(endpoint)[2],
y = "Euro",
x = "Health promotion decision"
)
 
</rcode>


==See also==
==See also==

Latest revision as of 20:01, 24 March 2015



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

Answer

Conclusions

Results

Not yet available.

Rationale

The causal diagram for the training assessment.

Assessment-specific data

Decisions
Decisions(-)
ObsDecisionmakerDecisionOptionVariableCellChangeUnitAmountDescription
1FactoryCleaning_policyBAUexposureYear:2020Multiply-1
2FactoryCleaning_policyReduce emissionsexposureYear:2020Multiply-0.5
3FactoryCleaning_policyBAUcostsAdd0
4FactoryCleaning_policyReduce emissionscostsYear:2020;Expenditure:Cleaning equipment useAdd30000-40000
5City of KuopioHealth_promotionBAUhealth_impactMultiply-1
6City of KuopioHealth_promotionIncrease health educationhealth_impactMultiply-0.9
7City of KuopioHealth_promotionBAUcostsAdd0
8City of KuopioHealth_promotionIncrease health educationcostsYear:2020;Expenditure:Health promotion campaignAdd10000


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

What is the unit cost of one case of disease?:

+ Show code

Explanations of the code

 <rcode graphics=1 
 	variables="name:unitcost|description:What is the unit cost of one case of disease?|type:text|default:100"
 >

The tag above starts the R code. It turns on the graphics so that graphs can be drawn. It also asks the user to give a value for the variable unitcost.

library(OpasnetUtils)
library(ggplot2)

In the beginning of a code, packages that are needed are loaded. These are the two most commonly used. OpasnetUtils is for all Opasnet functionalities, ggplot2 is for cool graphs.

DecisionTableParser(opbase.data("Op_en5677", subset = "Decisions")) # [[Training assessment]]

This code defines from where to take the assessment-specific decisions. In this case, they are on the page Training assessment, in a table called Decisions. The page has identifier Op_en5677, which can be found from the metadata box, which is typically in the top right corner of a page.

objects.latest("Op_en5675", code_name = "initiate") # [[Training health impact]] health_impact
objects.latest("Op_en5871", code_name = "initiate") # [[Training costs]] costs

These lines fetch ready-made ovariables that are needed in this assessment. The code defining these ovariables are located on the pages mentioned. Note that # is the comment character and everything after it is ignored in the model; so it is used to put explanations for the reader within the code.

unitcost <- Ovariable("unitcost", data = data.frame(Result = unitcost))

Unitcost was asked from the user as a value, and now it is converted to an ovariable.

costs <- EvalOutput(costs)

costs2 <- oapply(unkeep(costs, sources = TRUE), cols ="Expenditure", FUN = sum)

Because all ovariables are connected in the model, it is enough to evaluate the last one. The model will automatically evaluate all ovariables that are causally upstream. Also, the decisions that apply to this assessment will change the results of the ovariables as necessary. Ovariable costs2 is used to summarise contents of costs for easier presentation.

cat("Summary of health impacts\n")

Function cat is used to print outputs for the user.

oprint(summary(health_impact), digits = 0)

Function oprint is used to print tables for the user.

cat("Summary of all costs\n")

oprint(summary(costs2), digits = 0)
ggplot(exposure@output, aes(x = exposureResult, colour = Year)) + geom_density() +
	theme_gray(base_size = 24) +
	facet_grid(Cleaning_policy ~ .)

Function ggplot is very effective in creating all kinds of graphs with just a few lines. It is really worth learning.

ggplot(health_impact@output, aes(x = health_impactResult, colour = Year)) + geom_density() +
	theme_gray(base_size = 24) +
	facet_grid(Cleaning_policy ~ Health_promotion)

ggplot(subset(costs2@output, Year == 2020), aes(x = costsResult, colour = Payer)) + geom_density() +
	theme_gray(base_size = 24) +
	facet_grid(Cleaning_policy ~ Health_promotion)
 </rcode>

The code must always end with this tag.

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>