Skip to content
Prev 177155 / 398503 Next

nls factor

Oops! I made a mistake. Corrected below.
On Wed, 2009-04-15 at 11:05 -0400, Manuel Morales wrote:
call the factor f instead of a:
f <- gl(n=2, k=n/2) # a two-level factor
change equation to reflect above change:
y <- as.numeric(f) * x^.5 + eps
most importantly, fix syntax:
nls(y ~ a[fac]*x^b, start=list(a=c(1,1), b=0.25))

Altogether:
n <- 200
set.seed(123)
x <- runif(n)
f <- gl(n=2, k=n/2) # a two-level factor 
eps <- rnorm(n, sd=0.5)
y <- as.numeric(f) * x^.5 + eps 

nls(y ~ a[fac]*x^b, start=list(a=c(1,1), b=0.25))

Sorry for any confusion!

Manuel