Difference between revisions of "OpasnetUtils/Oassessment"

From Testiwiki
Jump to: navigation, search
(code replaced with link to code)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
[[Category:Opasnet]]
 
[[Category:Opasnet]]
 
[[Category:R tools]]
 
[[Category:R tools]]
 +
[[Category:OpasnetUtils]]
 
{{method|moderator=|stub=Yes}}
 
{{method|moderator=|stub=Yes}}
  
Line 14: Line 15:
  
 
==Code==
 
==Code==
<rcode
 
name="make.oassessment"
 
label="Initiate functions"
 
graphics="1"
 
>
 
  
# MAKE.OASSESSMENT ########## make.oassessment creates S4 assessment from dependencies data.frame, including decisions, stakeholders, probabilities, and variables.
+
https://www.opasnet.org/svn/opasnet_utils/trunk/R/OAssessment.r
########### NOTE! You must include the formula code from each variable page, otherwise formulas and dependencies are not updated.
 
########### Parameters:
 
## dependencies: a data.frame that has the structure of oassessment@name (Columns: Name, Identifier, Direction, Result)
 
make.oassessment <- function(x) {
 
x  <- fetch(x)
 
decisions    <- fetch(x[x$Result == "decisions",    "Identifier"])
 
stakeholders  <- fetch(x[x$Result == "stakeholders",  "Identifier"])
 
probabilities <- fetch(x[x$Result == "probabilities", "Identifier"])
 
dependencies  <- x[!x$Result %in% c("decisions", "stakeholders", "probabilities"), ]
 
vars          <- list()
 
for(i in 1:nrow(dependencies)) { # Objects with names as aliases are created and filled with data from Opasnet Base.
 
cat("Initialising variable ", as.character(dependencies$Name[i]), ".\n", sep = "")
 
ident <- as.character(dependencies$Identifier[i])
 
data <- fetch(ident, direction = as.character(dependencies$Direction[i]))
 
if(exists(paste("formula.", ident, sep = "")))
 
{formula <- get(paste("formula.", ident, sep = ""))
 
} else {
 
formula <- function(dependencies) {return(0)}
 
}
 
if(exists(paste("dependencies.", ident, sep = "")))
 
{depend <- get(paste("dependencies.", ident, sep = ""))
 
} else {
 
depend <- data.frame()
 
}
 
vars[[i]] <- make.ovariable(
 
name = as.character(dependencies$Result[i]),
 
data = data,
 
formula = formula,
 
dependencies = depend
 
)
 
}
 
names(vars) <- dependencies$Result
 
assessment <- new("oassessment",
 
dependencies  = dependencies,
 
decisions    = decisions,
 
stakeholders  = stakeholders,
 
probabilities = probabilities,
 
vars          = vars
 
)
 
 
 
return(assessment)
 
}
 
 
 
</rcode>
 
 
 
 
 
 
 
=setclass.oassessment=
 
==Description==
 
Defines the S4 class "oassessment" which is the object type for open assessments.
 
 
 
==Code==
 
<rcode
 
name="setclass.oassessment"
 
label="Initiate functions"
 
graphics="1"
 
>
 
 
 
# SETCLASS OASSESSMENT ################### Defines the S4 class "oassessment" which is the object type for open assessments.
 
temp <- setClass(
 
"oassessment",
 
representation(
 
dependencies  = "data.frame",
 
decisions    = "data.frame",
 
probabilities = "data.frame",
 
stakeholders  = "data.frame",
 
vars          = "list"
 
)
 
)
 
 
 
</rcode>
 
 
 
 
 
 
 
=movariable=
 
==Description==
 
movariable takes a data.frame, a function, and a list and makes an ovariable out of them. It is a subfunction of [[make.ovariable]] and prevents infinite recursion of S4 methods.
 
 
 
==Code==
 
<rcode
 
name="answer"
 
label="Initiate functions"
 
graphics="1"
 
>
 
library(OpasnetBaseUtils)
 
library(xtable)
 
 
 
n <- 5
 
 
 
# MOVARIABLE ########## movariable takes a data.frame, a function, and a list and makes an ovariable out of them. It is a
 
#####subfunction of make.ovariable and prevents infinite recursion of S4 methods.
 
movariable <- function(
 
data,
 
formula,
 
dependencies,
 
name
 
) {
 
output <- interpret(data)
 
out <- new("ovariable",
 
name        = name,
 
output      = output,
 
data        = data,
 
marginal    = ifelse(colnames(output) %in% c("Result", "Unit"), FALSE, TRUE),
 
formula      = formula,
 
dependencies = dependencies
 
)
 
out <- update(out)
 
return(out)
 
}
 
 
 
 
 
</rcode>
 
  
 
==See also==
 
==See also==

Latest revision as of 13:39, 16 August 2012



make.oassessment

Description

make.oassessment creates S4 assessment from dependencies data.frame, including decisions, stakeholders, probabilities, and variables.

NOTE! You must include the formula code from each variable page, otherwise formulas and dependencies are not updated.

Parameters

Dependencies

  • a data.frame that has the structure of oassessment@name (Columns: Name, Identifier, Direction, Result)

Code

https://www.opasnet.org/svn/opasnet_utils/trunk/R/OAssessment.r

See also