[R] Extracting equation from R code
tpet
tiago.peterlevitz at uol.com.br
Tue Oct 18 06:47:31 CEST 2011
Dear R-helpers,
I am trying to extract two equations from an R code, but I am not being able
to do it. The code is this:
function (x, fullin, fullout, crossover, infz = 0.953, outfz = 0.047,
details = FALSE)
{
if (fullin < fullout || crossover < fullout || fullin < crossover)
stop("It should be that: fullin > crossover > fullout.")
var.dev <- x - crossover
inLogOdd <- log(infz/(1 - infz))
outLogOdd <- log(outfz/(1 - outfz))
inScalar <- inLogOdd/(fullin - crossover)
outScalar <- outLogOdd/(fullout - crossover)
scalars <- rep(NA, length(x))
scalars[var.dev > 0] <- inScalar
scalars[var.dev < 0] <- outScalar
product <- scalars * var.dev
fz <- exp(product)/(1 + exp(product))
if (details) {
ans <- data.frame(x = x, deviations = var.dev, scalars = scalars,
logOdd = product, membership = fz)
}
else ans <- fz
ans
}
I would like to write the equations for fz as a function of x, fullin,
fullout, and crossover. I believe the code and the math aren’t that
difficult for many of you. Though as you can see, they are for me. The
equations I could arrive at are the following, but I know they are wrong as
their results aren’t the same as the ones derived from the code:
fz = exp(log(0.953/(1 – 0.953))/(fullin - crossover)* (x -
crossover))/(1+exp(log(0.953/(1 – 0.953))/(fullin - crossover)* (x -
crossover)))
for x > crossover
and
fz = exp(log(0.047/(1 – 0.047))/(fullout - crossover)* (x -
crossover))/(1+exp(log(0.047/(1 – 0.047))/( fullout - crossover)* (x -
crossover)))
for x < crossover
Does anyone have any ideas about the right equations?
Thank you,
Tiago
--
View this message in context: http://r.789695.n4.nabble.com/Extracting-equation-from-R-code-tp3914247p3914247.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list