xavier.chardon at free.fr
2009-May-06 12:22 UTC
[R] model fitting using by(): how to get fitted values?
Hi all, I'm doing nonlinear regressions on data with several factors. I want to fit say a logistic curve with different parameter values for each factor level. So I'm doing something like: tmp <- by( myData, list(myFactor1, myFactor2), function(x) nls(...) ) It works fine. However, I could not find an easy way to retrieve fitted values. I can use fitted() on each element of tmp, but that gives me as many vectors as there are combinations of factor levels. I was thinking of using by() again, but I can't figure out how to write it properly. Any ideas? Thanks a lot, Xavier
Duncan Murdoch
2009-May-06 12:29 UTC
[R] model fitting using by(): how to get fitted values?
On 06/05/2009 8:22 AM, xavier.chardon at free.fr wrote:> Hi all, > > I'm doing nonlinear regressions on data with several factors. I want to fit say a logistic curve with different parameter values for each factor level. So I'm doing something like: > > tmp <- by( myData, list(myFactor1, myFactor2), function(x) nls(...) ) > > It works fine. However, I could not find an easy way to retrieve fitted values. I can use fitted() on each element of tmp, but that gives me as many vectors as there are combinations of factor levels.I think lapply() (or maybe sapply) will do what you want. I haven't tried this, but it should be something like lapply(tmp, fitted) Duncan Murdoch> > I was thinking of using by() again, but I can't figure out how to write it properly. > > Any ideas? > > > Thanks a lot, > > Xavier > > ______________________________________________ > R-help at 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.