4-real
2010-Mar-22 15:31 UTC
[R] maxNR - Error in p(a, b) : element 1 is empty; the part of the args list of '*' being evaluated was: (b, t)
Hello everyone... We were trying to implement the Newton-Raphson method in R, and estimate the parameters a and b, of a function, F, however we can't seem to implement this the right way. Hope you can show me the right way to do this. I think what we want R to do is to read the data from the website and then peform maxNR on the function, F. Btw the version of R being used is "RGui for Windows" if it helps to know this. R-code below: library(maxLik)> require(maxLik) > > x <- > read.table('http://www.math.ku.dk/kurser/2008-09/blok4/stat2/doku/data/Eksempel_6_3.txt', > header = TRUE); > t <- log(x$Koncentration); > X <- x$Status; > > p <- function(a,b) exp(a+b*t)/(1+exp(a+b*t)); > S <- sum(X); > SP <- sum(t*X); > > F <- function(a,b) {+ c(sum(p(a,b)) - S, + sum(t*p(a,b)) - SP) + }> > > z <- maxNR(F, start=1, print.level=2)Error in p(a, b) : element 1 is empty; the part of the args list of '*' being evaluated was: (b, t)>Thanks and best regards. -- View this message in context: http://n4.nabble.com/maxNR-Error-in-p-a-b-element-1-is-empty-the-part-of-the-args-list-of-being-evaluated-was-b-t-tp1677790p1677790.html Sent from the R help mailing list archive at Nabble.com.
Arne Henningsen
2010-Mar-23 09:20 UTC
[R] maxNR - Error in p(a, b) : element 1 is empty; the part of the args list of '*' being evaluated was: (b, t)
On 22 March 2010 16:31, 4-real <danielkjaer90 at gmail.com> wrote:> > Hello everyone... > We were trying to implement the Newton-Raphson method in R, and estimate the > parameters a and b, of a function, F, however we can't seem to implement > this the right way. Hope you can show me the right way to do this. I think > what we want R to do is to read the data from the website and then peform > maxNR on the function, F. Btw the version of R being used is "RGui for > Windows" if it helps to know this. > > R-code below: > > ?library(maxLik) >> require(maxLik) >> >> x <- >> read.table('http://www.math.ku.dk/kurser/2008-09/blok4/stat2/doku/data/Eksempel_6_3.txt', >> header = TRUE); >> t <- log(x$Koncentration); >> X <- x$Status; >> >> p <- function(a,b) exp(a+b*t)/(1+exp(a+b*t)); >> S <- sum(X); >> SP <- sum(t*X); >> >> F <- function(a,b) { > + ? ? c(sum(p(a,b)) - S, > + ? ? ? sum(t*p(a,b)) - SP) > + } >> >> >> z <- maxNR(F, start=1, print.level=2) > Error in p(a, b) : element 1 is empty; > ? the part of the args list of '*' being evaluated was: > ? (b, t)You forgot to provide argument "b" for function "F": R> z <- maxNR(F, start=1, b=1, print.level=2) ----- Initial parameters: ----- fcn value: -15.42843 parameter initial gradient free [1,] 1 -22.49016 1 Condition number of the (active) hessian: 1 -----Iteration 1 ----- -----Iteration 2 ----- -----Iteration 3 ----- -----Iteration 4 ----- -----Iteration 5 ----- -----Iteration 6 ----- -------------- gradient close to zero. May be a solution 6 iterations estimate: -0.6288598 Function value: -1.536789 /Arne -- Arne Henningsen http://www.arne-henningsen.name