Skip to content
Prev 290270 / 398498 Next

indexing in a function doesn't work?

Josh,

Many thanks - here's a subset of the data and a couple examples:

plotter(10,3,fram=rwb,framvec=rwb$prcnt.char.depth,obj=prcnt.char.depth,form1=
post.f.crwn.length~shigo.av,form2=post.f.crwn.length~shigo.av-1,
form3=leaf.area~(1/exp(shigo.av*x))*n,type=2,xlm=70,ylm=35)

plotter(10,3,fram=rwb, framvec=rwb$prcnt.char.depth, obj=prcnt.char.depth,
form1= post.f.crwn.length~leaf.area, form2=post.f.crwn.length~leaf.area-1,
form3=leaf.area~(1/exp(shigo.av*x))*n,type=1, xlm=1500, ylm=35,
sx=.01,sn=25)




plotter<-function(a,b,fram,framvec,obj,form1,form2,form3, type=1, xlm, ylm,
sx=.01,sn=25){
g<-ceiling(a/b)
par(mfrow=c(b,g))
num<-rep(0,a)
sub.plotter<-function(i,fram,framvec,obj,form1,form2,form3,type,
xlm,ylm,var1,var2){
temp.i<-fram[framvec <=(i*.10),] #trees in the list that have an attribute
less than or equal to a progressively larger percentage
 plot(form1, data=temp.i, xlim=c(0,xlm), ylim=c(0,ylm), main=((i-1)*.10))
if(type==1){
 mod<-lm(form2,data=temp.i)
r2<-summary(mod)$adj.r.squared
num[i]<-r2
 legend("bottomright", legend=signif(r2), col="black")
abline(mod)
 num}
else{
if(type==2){
 try(mod<-nls(form3, data=temp.i, start=list(x=sx,n=sn),
na.action="na.omit"), silent=TRUE)
try(x1<-summary(mod)$coefficients[1,1], silent=TRUE)
 try(n1<-summary(mod)$coefficients[2,1], silent=TRUE)
try(lines((1/exp(c(0:70)*x1)*n1)), silent=TRUE)
 try(num[i]<-AIC(mod), silent=TRUE)
try(legend("bottomright", legend=round(num[i],3) , col="black"),
silent=TRUE)
 try((num), silent=TRUE)
  }
}}
for(i in 0:a+1){
 num<-sub.plotter(i,fram,framvec,obj,form1,form2,form3,type,xlm,ylm)
}
plot.cor<-function(x){
temp<-a+1
lengthx<-c(1:temp)
plot(x~c(1:temp))
m2<-lm(x~c(1:temp))
abline(m2)
n<-summary(m2)$adj.r.squared
legend("bottomright", legend=signif(n), col="black")
slope<-(coef(m2)[2])# slope
values<-(num)#values for aic or adj r2
r2ofr2<-(n) #r2 of r2 or AIC
output<-data.frame(lengthx,slope,values,r2ofr2)
}
plot.cor(num)
write.csv(plot.cor(num)$output,"output.csv") # can't seem to use
paste(substitute(form3),".csv",sep="") to name it at the moment
par(mfrow=c(1,1))
}
On Sun, Apr 1, 2012 at 3:25 PM, Joshua Wiley <jwiley.psych at gmail.com> wrote: