Hi all, I'm trying to fit a model using the shorthand coeff[factor] instead of coding dummy variables. Is there a way to keep this notation when specifying constraints? See example below:
x = runif(200) b0 = c(rep(0,100),runif(100)) b1 = 1 fac <- as.factor(rep(c(0,1), each=100)) y = b0+b1*x+rnorm(200,sd=0.05) ## No constraint - works nls(y~b0[fac]+b1*x, start=list(b0=c(1,1),b1=1),algorithm="port") ## Constraint - doesn't work nls(y~b0[fac]+b1*x, start=list(b0=c(1,1),b1=1), algorithm="port", upper=c(100,100,.5)) ## Constraint w/ dummy variable - works nls(y~b01+I(as.numeric(fac)-1)*b02+b1*x, start=list(b01=1,b02=1,b1=1), algorithm="port", upper=c(100,100,.5)) Thanks! Manuel -- http://mutualism.williams.edu
signature.asc
Description: This is a digitally signed message part
______________________________________________ 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.