Training health impact

From Opasnet
Revision as of 19:46, 1 January 2013 by Jouni (talk | contribs) (technical edits)
Jump to navigation Jump to search



Question

What is the health impact in the Training assessment?

Answer

Default run: ypckOigfNjlYPKhE

Rationale

Data

Training health impact(-)
ObsYearUnitResultDescription
12012cases /a10 - 100
22020cases /a15 - 150

Formula

+ Show code

Explanations

First, you start the rcode by using the rcode tag. You may change the text that shows on the run button by using the parameter label. You may also define user input form by using the parameter variable (not used here).

<rcode 
	label="Initiate functions" 
>

Then, you define the libraries (or packages) that you want to use. You almost always need the library OpasnetUtils, and if you want to show decent tables in the model output, you also need xtable. If you want to draw graphs, you probably need ggplot2.

library(OpasnetUtils)
library(xtable)

With few exceptions, each Opasnet page used in a model has an R code that creates an information object, called ovariable. The object answers to the question presented on that page. In effect, it is equal to the answer of the page, but described in a way that it can be understood by a computer running models. An ovariable is properly defined only if it is possible to calculate the answer for the question. You can calculate the answer by using either measurement data about the issue or dependencies and formula. Dependencies are other objects that you can use to calculate (rather than directly measure) the answer. How to use dependencies to calculate the answer, that is described in the formula.

Data, dependencies, and formula are parts of an ovariable. They are called slots. On this page, we define an object called health.impact. It contains these three slots and a few others. In an R code, you can refer to a slot by adding the name of the slot after the name of the ovariable, separated by @: health.impact@data. If you want to refer to a column within a table in a slot, you say e.g. health.impact@dependencies$Name.

The slot dependencies is a data.frame (a kind of a table) with Name and Key as the two columns, while formula is a function. Data is also a data.frame but it is more flexible about the names and amount of columns in it. Typical columns are Unit and Result.

Dependencies is defined by using the function data.frame, to which the names of columns and then the content of the columns are given. c() is a function that creates a vector (a kind of list of numbers or text strings in a specified order). In this case, the vectors (or columns) Name and Key have only one row.

dependencies.input <- data.frame(
	Name = c("exposure"),
	Key = c("muRtYjhkphoNPQJI")
)

Functions are defined in a way that you first give the name of the new function, then you list its parameters. In this case, the only parameter defined is dependencies, but the three dots ... indicate that other parameters can be given by the user.) After this is a description about what the function actually does. In practice, all formulas have the same first row that forces a formula to compute its dependencies first. So, remember to copy-paste the first row to your code, whatever your formula does. In this example, the formula defines three constants and then takes exposure from the dependencies; in other words, the exposure comes from another ovariable defined elsewhere. The number of cases of a health impact are calculated using there constants and the exposure. Finally the calculated number of cases is returned from the function.

formula.input <- function(dependencies, ...) {
	ComputeDependencies(dependencies, ...)
	erf <- 1.5 # RR per ug / m3

	background <- 100 / 100000 # cases per 100000 person-years
	
	population <- 50000
	
	cases      <- exposure * population * background * (erf - 1)
	return(cases)
}

In this case, data is defined by downloading a ready-made table from the Opasnet Base. Tidy and op_baseGetData are functions that actually do the downloading. For now, it is enough to say that you can just copy the code to another place and replace "Op_en5675" with the identifier of your page and "health.impact" with the name you want to give to your ovariable. In most cases it works even if you don't know all the details.

data.input <- tidy(op_baseGetData("opasnet_base", "Op_en5675"), "health.impact")

Now we have come to the place we we have done the background work and we actually create our ovariable called health.impact. Again, you can copy-paste this code to other places and just replace the parts you need. An ovariable works properly only if you have defined either data or dependencies together with formula. You can define all of them if they are available.

health.impact <- new("ovariable",
	name         = "health.impact",
	formula      = formula.input,
	dependencies = dependencies.input,
	data         = data.input
)

The final part of the code is the actual computing. EvalOutput is a function that calculates the output of an ovariable, based on data or dependencies, whichever is available. If the dependencies themselves depend on other objects, they are fetched and evaluated as well, and if they have dependencies, they are also fetched and so on, until everything that is needed is fetched. The parameter N = 10 tells the number of Monte Carlo iterations that are used. First, you should start with rather low numbers until you see that the model has not grown too large.

You probably want to print or plot model outputs. in this example, the output table is printed on screen. You can search for ggplot within Opasnet to find out pages where different kinds of plots have been used. Often, you can just copy-paste the code with ggplot2 function to your own code, change the names of the objects you use, and you get fancy plots in no time!

Finally, the ovariable you have created is saved onto the Opasnet server by using the function objects.put. You can call that particular object in the particular run by copying the key from the url to a dependencies table of some other ovariable. In this example, the upstream dependency object exposure was created in a model run with the key muRtYjhkphoNPQJI. If you want to go back to that run, you can use the key in this way:

http://en.opasnet.org/en-opwiki/index.php/Special:R-tools?id=muRtYjhkphoNPQJI

out <- EvalOutput(health.impact, N = 10)

print(xtable(out@output), type = "html")

objects.put(health.impact)
</rcode>

Remember to close your rcode by using the end tag </rcode>.

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


Keywords

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>