"nelson -" <nelson1977 at gmail.com> writes:
> Hi all!
> i'm trying to use nls for fitting my data. I wrote this code to find
> some minimum, but it fails, returning 0 every time..... and i can't
> figure out the problem... any advice?
>
> grid <- expand.grid(A0 = seq(1000,10000,1000), A1 = seq(0,2,0.1))
> exp.approx <- function(x,A0,A1) {
> A0 * exp(- x*A1)
> }
> ss <- function(p) {
> sum((durata.h.freq -
exp.approx(durata.h.x,p[0],p[1]))^2)}
>
> idx <- which.min(apply(grid,1,ss))
>
>
>
> idx is always 1,1... and that's not true...
Array indexing in R is 1-based, so p[0] is asking for trouble....
--
O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907