Extracting equation from R code
I checked your equations with some made-up values:
crossover <- 50
fullin <- 120
fullout <- 20
x <- 62
and got 0.6261906 --- which was the value returned by the function in
question.
With x <- 41 I got 0.3094857 --- again the same as the value returned by
the function.
So you seem to have derived the equations correctly. Why did you think
there was an error?
cheers,
Rolf Turner
On 18/10/11 17:47, tpet wrote:
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.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.