[R] nls question continued
gb@stat.umu.se
gb at stat.umu.se
Tue Feb 15 17:19:42 CET 2000
Douglas,
Thank you for the prompt answer. However, I still have
difficulties, see below.
On 14 Feb 2000, Douglas Bates wrote:
> gb at stat.umu.se writes:
>
> > I have two functions, tids1 and tids2:
> >
> > tids1 <- function(W, w)
> > {
> > nls(W ~ w %*% beta,
> > data = parent.frame(0),
> > start = list(beta = rep(0, ncol(w)) ) )
> > }
> >
> > tids2 <- function(W, w)
> > {
> > X.1 <- w[, 1]
> > X.2 <- w[, 2]
> >
> > nls(W ~ X.1 * beta1 + X.2 * beta2,
> > data = parent.frame(0),
> > start = list(beta1 = 0, beta2 = 0))
> > }
> >
> > I want something like tids1, but only tids2 works:
> >
> > > tids1(Y, X)
> > Error in qr.qty(QR, resid) : qr and y must have the same number of rows
> >
> > > tids2(Y, X)
> > Nonlinear regression model
> > model: W ~ X.1 * beta1 + X.2 * beta2
> > data: parent.frame 0
> > beta1 beta2
> > 1.200331 1.027278
> > residual sum-of-squares: 5.358129
> >
> > Q: How do I write a _general_ tids2?
>
> The nls function has an argument "algorithm" which can be set to
> "plinear" for partially linear models. This will fits exactly this
> kind of model, assuming that the matrix w itself depends on some
> parameters (if it doesn't you have a linear regression model and no
> need to use nls).
>
> Look at
> example(nls)
> to see how that argument is used.
>
>
> nls> fm2DNase1 <- nls(density ~ 1/(1 + exp((xmid - log(conc))/scal)),
> data = DNase1, start = list(xmid = 0, scal = 1), alg = "plinear",
> trace = TRUE)
> 0.7139315 : 0.000000 1.000000 1.453853
> 0.1445295 : 1.640243 1.390186 2.461754
> 0.008302151 : 1.620899 1.054228 2.478388
> 0.004794192 : 1.485226 1.043709 2.347334
> 0.004789569 : 1.483130 1.041468 2.345218
> 0.004789569 : 1.483090 1.041455 2.345180
This works alright, but what if you want to use 'data = DNase' instead,
and include DNase$Run as a factor in the model, for instance linearly?
This is close to my _real_ problem, where the model is something like
y ~ (x.1 * beta1 + x.2 * beta2)^delta + X %*% Alpha
where X is a matrix created from indicators of the levels of a
factor. 'delta' is a known constant, beta1 and beta2 are scalar
parameters, and Alpha is vector of parameters.
Could this be done?
Göran
----------------------------------------------------------
Göran Broström tel: +46 90 786-5223
Department of Statistics fax: +46 90 786-6614
Umeå University
SE-90187 Umeå, Sweden email: gb at stat.umu.se
http://www.stat.umu.se/egna/gb ftp://capa.stat.umu.se
----------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list