Hi all,

I'm adjusting a nonlinear regression model for data that has a categorigal
variable present. So, I can use nls() to do this considering the categorical
variable, like this

#------------------------------------------------------------
da <- expand.grid(tr=gl(2,1,la=c("tr")), x=1:12)
da$y <- 10*da$x/(3+da$x)+rnorm(da$x,0,0.1)
plot(y~x, da)

n0 <- nls(y~A[tr]*x/(B[tr]+x), data=da,
          start=list(A=c(10,10), B=c(3,3)), trace=TRUE)
summary(n0)
attr(n0$m$fitted(), "gradient")
attr(n0$m$fitted(), "hessian")
#------------------------------------------------------------

but I want specify a model using deriv3() function because I use the
gradient and hessian of the model fit

#------------------------------------------------------------
model <- deriv3(~A*x/(B+x), c("A","B"), function(x, A, B) NULL)
n1 <- nls(y~model(x, A, B), data=da,
          start=list(A=c(10), B=c(3)), trace=TRUE)
summary(n1)

attr(n1$m$fitted(), "gradient")
attr(n1$m$fitted(), "hessian")
#------------------------------------------------------------

How can I declare that categorical variable in my adjust using deriv3()
method? My try was

#------------------------------------------------------------
> n2 <- nls(y~model(x, A[tr], B[tr]), data=da,
+           start=list(A=c(10,10), B=c(3,3)), trace=TRUE)
0.2446993 :  10 10  3  3
0.2366604 :  9.887467 9.916289 3.000000 3.000000
Erro em nls(y ~ model(x, A[tr], B[tr]), data = da, start = list(A = c(10,  :

  fator de passos 0.000488281 reduzido abaixo de 'minFactor' de 0.000976562
#------------------------------------------------------------

That indicates the categorical variable was accounted. But values of B
didn't change during iteration. Why?

Thanks,
Walmes.

==========================================================================
Walmes Marques Zeviani
LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)
Departamento de Estatística - Universidade Federal do Paraná
fone: (+55) 41 3361 3573
VoIP: (3361 3600) 1053 1173
e-mail: wal...@ufpr.br
twitter: @walmeszeviani
homepage: http://www.leg.ufpr.br/~walmes
linux user number: 531218
==========================================================================

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to