[R] Error meaning
Berend Hasselman
bhh at xs4all.nl
Wed Jan 20 16:28:52 CET 2010
Roslina Zakaria wrote:
>
> I have the following code to solve 4 simultaneous eqns with 4 unknowns
> using newton iteration method. But I got the error message:
>
> pars <- c(1.15, 40, 50, 0.78)
> newton.input2 <- function(pars)
> { ## parameters to estimate
> .......
>
> f1 <- pars[1]*pars[2]
> f2 <- pars[1]*(pars[1]+1)*pars[2]^2
> f3 <- pars[1]*(pars[1]+1)*pars[3]^2
> f4 <- pars[1]*pars[2]*pars[3](pars[1]+pars[4])
> fval <- c(f1,f2,f3,f4)
> ## jacobian matrix
> ....
> list(fval=fval,jacobian=jacobian)
> }
> newton.input2(pars)
> newt(newton.input2, c(1,20,30,0.5))
>
> Note: I use 'newt' code is develope by Rolf Turner.
> Error message:
>
>> newton.input2(pars)
> Error in newton.input2(pars) : attempt to apply non-function
>> newt(newton.input2, c(1,20,30,0.5))
> Error in fn(p.o, ...) : attempt to apply non-function
>
I agree with David.
The formula for f4 is surely incorrect.
Furthermore:
1. what is the newt package you mention. I can't find it on CRAN.
2. A solution of your system is pars = [ 0, anything, anything, anything ]
(if pars[1] == 0 then all f-values will also be 0 regardless of values
for pars[2:4])
There are more solutions to your system (try pars = c(-1 , 0, 0, 0)).
3. The jacobian you generate is incorrect
4. I tried to solve your system with the correction mentioned above with my
package nleqlsv.
I have to change the return value of your function newton.input2 to only
return fval.
Using Broyden and a numerical jacobian. As far as I can see, this
confirms the point I made in item 2.
pars[1] = 0 with arbitrary values in pars[2], pars[3], pars[4] is a
solution.
Berend
--
View this message in context: http://n4.nabble.com/Error-meaning-tp1018287p1018468.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list