[R] nls question
Douglas Bates
bates at stat.wisc.edu
Tue Feb 15 00:46:21 CET 2000
=?ISO-8859-1?Q?G=F6ran_Brostr=F6m?= <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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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