[R] for loop in nls function

From: Ingrid Tohver <itohver_at_u.washington.edu>
Date: Tue, 29 Apr 2008 14:22:23 -0700


Hello,
I am trying to apply a least squares non-linear regression to my dataset, dem16. I can apply it to a subset based on a single site fine, but I want to apply it to each (of 197) sites. I am stumbling over a "for" loop. Site and Mean_Air are variables in my dataset and I would like to estimate alpha, beta, gamma, mu and Tw for each site. I have over 50,000 observations in my dataset.

results <- c()
for (i in Site) {
results[i]<- nls(Tw ~ mu + ((alpha - mu)/(1 + exp(gamma*(B - Mean_Air)))),

	data = dem16,
	start = list(mu = 0.0001, alpha = 21.8, gamma = 0.22, B = 12.8))
	}

Thank you in advance,
Ingrid



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. Received on Tue 29 Apr 2008 - 22:53:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Apr 2008 - 02:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive