[R] for loop in nls function

Ingrid Tohver itohver at u.washington.edu
Tue Apr 29 23:22:23 CEST 2008


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



More information about the R-help mailing list