[R] help with a for loop
Quan Li
quanli at mail.ucf.edu
Wed Oct 15 21:56:29 CEST 2008
Hi all,
I am running OLS models with a power parameter: y=a+bx^p, and I want to iterate through p with a set increment. The function I constructed is something like below:
test<-function(data, model,...){
f<-formula(model) #model="y~I(x^p)"
p<-0.1
n<-10
result<-list()
while (p<=1) {
for (i in 1:n) {
result[[i]]<-lm(data, formula=f...)
p<-p+0.1
}
}
return(result)
}
The problem I am facing is that the loop does not assign or update p values. I also tried a nested for loop starting with "for (p in seq(0.1,1,0.1)){for (i in 1:n) {..." but it did not work either. After the initial value of p is assigned, the inner loop is executed but p is not updated. Any help is greatly appreciated.
best,
quan
More information about the R-help
mailing list