[R] Error meaning

David Winsemius dwinsemius at comcast.net
Wed Jan 20 15:50:48 CET 2010


When I look at this line:

f4 <- pars[1]*pars[2]*pars[3](pars[1]+pars[4])

It appears to my wet-brain interpreter that you are trying to apply a  
function par[3] to the argument (pars[1]+pars[4])

When I insert a "*", I then get output but I don't know if it is  
correct.

 > newton.input2(pars)
$fval
[1]   46.00 3956.00 6181.25 4439.00

$jacobian
      [,1]      [,2]   [,3]  [,4]
[1,]   40      1.15      0 0e+00
[2,] 5280    197.80      0 0e+00
[3,] 8250    247.25      0 0e+00
[4,] 6160 126950.00 101560 1e+05
-- 
David
On Jan 20, 2010, at 4:58 AM, Roslina Zakaria wrote:

> Hi r-users,
>
> 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
>
>    alp <- pars[1]
>    b1  <- pars[2]
>    b2  <- pars[3]
>    rho <- pars[4]
>
> 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
> j11 <- pars[2]
> j12 <- pars[1]
> j13 <- 0
> j14 <- 0
> j21 <-  (2*pars[1]+1)*pars[2]^2
> j22 <-  2*pars[2]*pars[1]*(pars[1]+1)
> j23 <-  0
> j24 <-  0
> j31 <- (2*pars[1]+1)*pars[3]^2
> j32 <- 2*pars[3]*pars[1]*(pars[1]+1)
> j33 <- 0
> j34 <- 0
> j41 <- pars[2]*pars[3]*(2*pars[1]+pars[4])
> j42 <- pars[3]*(pars[3]^2+pars[3]*pars[4])
> j43 <- pars[2]*(pars[3]^2+pars[3]*pars[4])
> j44 <- pars[3]*pars[2]*pars[3]
> jacobian <-  
> matrix 
> (c 
> (j11 
> ,j12 
> ,j13 
> ,j14 
> ,j21,j22,j23,j24,j31,j32,j33,j34,j41,j42,j43,j44),byrow=TRUE,ncol=4)
> ## output
> 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.
>
> Thank you.
>
>
> 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
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list