Input.interp

From Testiwiki
Revision as of 13:46, 29 August 2011 by Jouni (talk | contribs) (first draft)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


input.interp is an R function that interprets model inputs from a user-friendly format into explicit and exact mathematical format. The purpose is to make it easy for a user to give input without a need to worry about technical modelling details.

Question

What should be a list of important user input formats, and how should they be interpreted?

Answer

n is the number of interations in the model.

Example Regular expression Output in R
50 - 125 # - # data.frame(obs=1:n, result=runif(n,50,125))
3.1 ± 1.2 # ± # data.frame(obs=1:n, result=rnorm(n,3.1,1.2))
2.4 (1.8 - 3.0) # (# - #) data.frame(obs=1:n, result=rnorm(n,2.4,(3.0-1.8)/2/1.96))#assumes normal distribution and 95 % CI
24 - 35 (odds 5:1) # - # (odds #:#) Interpretation: odds is five to one that the truth is between 24 and 35. How to calculate this, I don't know yet, but there must be a prior.

This table has been moved from Jatropaöljyn tuotanto maailmassa.

Opasnet-kannan tulosten muokkausfunktio
Tilanne Tavoite Ratkaisu
Result.text = "12 000" Result = 12000 as.numeric(gsub(" ", "", Result.text))
Result.text = "12,345" Result = 12.345 as.numeric(gsub(",", ".", Result.text)) #Huom! Pilkkua ei saa käyttää tuhaterottimena!
Result = c(0, 200), Result.text = c("1 500", NA) Result = c(1500, 200) Result.text <- as.numeric(gsub(" ", "", Result.text)); Result <- ifelse(is.na(Result.text), Result, Result.text)
Result.text = c("1 500", "800 - 1200") #Huom! Väliviiva pitää kirjoittaa irti luvusta, jottei luulla miinusmerkiksi. data.frame( range = c("lower", "upper", "lower", "upper"), Result = c(1500, 1500, 800, 1200)) temp <- strsplit(gsub(" ", "", Result.text), "-"); sel.vec <- rep(c(1,1), length(temp)); sel.vec[rep(sapply(temp, length) == 2, each = 2)] <- c(1,2); data.frame(Range = rep(c("lower", "upper"), length(temp)), Result = unlist(sapply(temp, as.numeric))[sel.vec + rep(cumsum(c(0, sapply(temp, length)[-length(temp)])), each = 2)])