|
|
| Rivi 9: |
Rivi 9: |
| Yli vuoden kokemuksella Opasnetin kanssa paininut. Pääasiassa olen koodannut malleja R:llä. | | Yli vuoden kokemuksella Opasnetin kanssa paininut. Pääasiassa olen koodannut malleja R:llä. |
|
| |
|
| ==R Koodi VedDesTeh== | | == R code test == |
|
| |
|
| <rcode | | <rcode showcode = "1"> |
| name="muuttuja"
| |
| label="Alusta muuttuja"
| |
| graphics="1"
| |
| include="
| |
| page:Opasnet_(R_library)|name:answer
| |
| > | |
| library(OpasnetUtils) | | library(OpasnetUtils) |
| library(xtable) | | library(xtable) |
| | | data <- op_baseGetData("opasnet_base", "Op_fi2806") # Haetaan päästökerrointiedot |
| temp <- tidy(op_baseGetData("opasnet_base", "Op_fi2993"), objname = "VedDesTeh")
| | print(xtable(data), type = "html") |
| print(xtable(temp), type = "html") | | data <- tidy(data) # Siistitään data |
| | | print(xtable(data), type = "html") |
| riippuvuudet <- data.frame(
| |
| Name = c("Klooraus"),
| |
| Key = c("n2YMZPHPrEi1HjD4")
| |
| )
| |
| | |
| funktio <- function(dependencies, ...) {
| |
| ComputeDependencies(dependencies, ...)
| |
| temp <- tidy(op_baseGetData("opasnet_base", "Op_fi2993"), objname = "VedDesTeh")
| |
| temp <- merge(
| |
| temp,
| |
| Klooraus@output[
| |
| ,
| |
| colnames(Klooraus@output) %in% c(colnames(temp), "KloorausSource", "KloorausResult")
| |
| ],
| |
| all = TRUE
| |
| )
| |
| temp$VedDesTehResult <- ifelse(
| |
| is.na(temp$KloorausResult),
| |
| temp$VedDesTehResult,
| |
| temp$KloorausResult
| |
| )
| |
| return(temp)
| |
| }
| |
| | |
| VedDesTeh <- new("ovariable",
| |
| name = "VedDesTeh",
| |
| data = temp,
| |
| dependencies = riippuvuudet,
| |
| formula = funktio
| |
| )
| |
| temp <- EvalOutput(VedDesTeh)
| |
| print(xtable(temp@output), type = "html")
| |
| variable <- temp
| |
| deps <- list()
| |
| priormarg <- TRUE
| |
| | |
| cat("Checking", variable@name, "marginals", "...")
| |
| varmar <- colnames(variable@data)[
| |
| !grepl(paste("^", variable@name, "", sep=""), colnames(variable@data))&
| |
| !colnames(variable@data) %in% c("Result", "Unit")
| |
| ]
| |
| # all locs under observation/parameter index should be excluded
| |
| varmar <- c(varmar, paste(variable@name, "Source", sep = "")) # Source is added
| |
| # by EvalOutput so it should always be in the initial list.
| |
| novarmar <- colnames(variable@data)[!colnames(variable@data) %in% varmar]
| |
| if (priormarg & length(variable@marginal) > 0) {
| |
| varmar <- unique(c(varmar, colnames(variable@output)[variable@marginal]))
| |
| novarmar <- unique(c(novarmar, colnames(variable@output)[!colnames(variable@output) %in% varmar]))
| |
| }
| |
| if (length(deps) > 0) {
| |
| for (i in deps) {
| |
| varmar <- unique(c(varmar, colnames(i@output)[i@marginal]))
| |
| novarmar <- unique(c(novarmar, colnames(i@output)[!i@marginal]))
| |
| }
| |
| } else {
| |
| for (i in as.character(variable@dependencies$Name)){
| |
| varmar <- unique(c(varmar, colnames(get(i)@output)[get(i)@marginal]))
| |
| novarmar <- unique(c(novarmar, colnames(get(i)@output)[!get(i)@marginal]))
| |
| }
| |
| }
| |
| varmar <- varmar[!varmar %in% novarmar]
| |
| variable@marginal <- colnames(variable@output) %in% varmar
| |
| if (sum(variable@marginal) > 0) {
| |
| cat(paste(colnames(variable@output)[variable@marginal], collapse = ", "), "recognized as marginal(s).\n")
| |
| } else {cat("none recognized.\n")}
| |
| #cat("done!\n")
| |
| | |
| | |
| | |
| | |
| temp <- CheckMarginals(temp)
| |
| cat(colnames(temp@output)[temp@marginal], "\n")
| |
| | |
| objects.put(VedDesTeh)
| |
| | |
| cat("Muuttuja alustettu. Kopioi sivun osoitteen avain talteen käyttöä varten.\n")
| |
| </rcode>
| |
| | |
| ==R Koodi PatPitPuhVed==
| |
| | |
| <rcode
| |
| name="muuttuja"
| |
| label="Alusta muuttuja"
| |
| graphics="1"
| |
| include="page:Opasnet_(R_library)|name:answer"
| |
| >
| |
| library(OpasnetUtils)
| |
| library(xtable)
| |
| library(reshape2)
| |
| | |
| riippuvuudet <- data.frame(
| |
| Name = c("RaaPatPitLuo", "VedDesTeh", "VedKasTeh"),
| |
| Key = c("AEmnj6ZNfhIHAt2X", "Ro8WEVdKjOEnxocT", "hdXm6afLzU4maZEo")
| |
| )
| |
| | |
| dependencies <- riippuvuudet#funktio <- function(dependencies, ...) {
| |
| ComputeDependencies(dependencies)#, ...)
| |
| print(xtable(VedDesTeh@output), type = "html")
| |
|
| |
| cat(colnames(VedDesTeh@output)[VedDesTeh@marginal], "\n")
| |
| #VedDesTeh <- dcast()
| |
| VedDesTeh@output <- as.data.frame(as.table(tapply(
| |
| VedDesTeh@output[["VedDesTehResult"]],
| |
| VedDesTeh@output[,VedDesTeh@marginal &
| |
| !colnames(VedDesTeh@output) %in% c("Menetelmä", "KloorausSource")],
| |
| sum
| |
| )))
| |
| print(xtable(VedDesTeh@output), type = "html") | |
| colnames(VedDesTeh@output)[colnames(VedDesTeh@output) %in% "Freq"] <- "VedDesTehResult"
| |
| VedDesTeh <- CheckMarginals(VedDesTeh)
| |
| cat(colnames(VedDesTeh@output)[VedDesTeh@marginal], "\n")
| |
|
| |
| VedKasTeh@output <- as.data.frame(as.table(tapply(
| |
| VedKasTeh@output[["VedKasTehResult"]],
| |
| VedKasTeh@output[,VedKasTeh@marginal &
| |
| !colnames(VedKasTeh@output) %in% "Vedenpuhdistusmenetelmä"],
| |
| sum
| |
| )))
| |
| print(xtable(VedKasTeh@output), type = "html")
| |
| colnames(VedKasTeh@output)[colnames(VedKasTeh@output) %in% "Freq"] <- "VedKasTehResult"
| |
| VedKasTeh <- CheckMarginals(VedKasTeh)
| |
|
| |
| out <- merge(RaaPatPitLuo, VedDesTeh)
| |
| out <- merge(out, VedKasTeh)
| |
|
| |
| attach(out@output)
| |
|
| |
| out@output$Result <- RaaPatPitLuoResult * 10 ^(-(VedDesTehResult + VedKasTehResult))
| |
| detach("out@output")
| |
| #out <- RaaPatPitLuo * 10 ^(0 - (VedDesTeh + VedKasTeh))
| |
| #return(out@output)
| |
| #}
| |
| | |
| #PatPitPuhVed <- new("ovariable",
| |
| # name = "PatPitPuhVed",
| |
| # dependencies = riippuvuudet,
| |
| # formula = funktio
| |
| #)
| |
| | |
| #temp <- EvalOutput(PatPitPuhVed, N = 1, substitute = TRUE)
| |
| | |
| #print(xtable(temp@output), type = "html")
| |
| | |
| #objects.put(PatPitPuhVed)
| |
| | |
| cat("Muuttuja alustettu. Kopioi sivun osoitteen avain talteen käyttöä varten.\n")
| |
| </rcode>
| |
| | |
| == R Koodi Infektio todennäköisyys ==
| |
| | |
| <rcode>
| |
| | |
| #laskee todennakoisyyden infectiolle
| |
| library(OpasnetUtils)
| |
| library(xtable)
| |
| riippuvuudet <- data.frame(
| |
| Name = c("Exposure", "PatAnnVas"),
| |
| Key = c("97X24ShLlNiDbdqi", "Em89Y0FEI8jtg7Tx")
| |
| )
| |
|
| |
| dependencies <- riippuvuudet#funktio <- function(dependencies, ...){
| |
| ComputeDependencies(dependencies)#, ...)
| |
|
| |
| out <- merge(PatAnnVas,Exposure, all = FALSE)
| |
| | |
| #print(xtable(out@output), type = "html")
| |
| | |
| #attach(out@output)
| |
| cat(class(out@output), "\n")
| |
| cat(class(out@output$ExposureResult), "\n")
| |
| cat(class(out@output[["ExposureResult"]][[1]]), "\n")
| |
| cat(out@output[["ExposureResult"]][[1]], "\n")
| |
| #print(xtable(out@output$ExposureResult), type = "html")
| |
| for(i in 1:nrow(out@output)){
| |
| cat(i, "\n")
| |
| cat(as.character(out@output$Rname[i]), "\n")
| |
| cat(out@output$ExposureResult[[1]][i], "\n")
| |
| cat(out@output$Param1[i], "\n")
| |
| cat(out@output$Param2[i], "\n")
| |
| out@output$Result[i] = get(as.character(out@output$Rname[i]))(out@output$ExposureResult[[1]][i],out@output$Param1[i],out@output$Param2[i])
| |
| }
| |
| #detach("out@output")
| |
| # return(out@output[, !colnames(out@output) %in% "out"])
| |
| #}
| |
| | |
| | |
| | |
| #ExpoPatAnn <- new("ovariable",
| |
| # name = "ExpoPatAnn",
| |
| # dependencies = riippuvuudet,
| |
| # formula = funktio
| |
| #)
| |
| | |
| #objects.put(ExpoPatAnn)
| |
| #print(xtable(EvalOutput(ExpoPatAnn)@output),type = "html")
| |
| #cat("Muuttuja alustettu. Kopioi sivun osoitteen avain talteen käyttöä varten.\n")
| |
| </rcode> | | </rcode> |