Skip to content

Instantly share code, notes, and snippets.

@ejjunju
Created February 14, 2014 15:48
Show Gist options
  • Save ejjunju/9003366 to your computer and use it in GitHub Desktop.
Save ejjunju/9003366 to your computer and use it in GitHub Desktop.
dat<-data.frame(x=Duration, y=as.numeric(idfkurve["2",]))
#polynomial fit
library(MASS)
LFts<-6
Fits<-vector("list",length=LFts)
for(i in 1:LFts){
Fits[[i]]$fit <-lm(y~poly(x,i),data=dat);
Fits[[i]]$col=i
Fits[[i]]$AIC=round(AIC(Fits[[i]]$fit ),0)
Fits[[i]]$coef=coef(Fits[[i]]$fit)
}
plot(dat$x,dat$y,pch=19,log="xy",cex=2,col="white")
plot(dat$x,dat$y,pch=19,cex=2,col="white")
L<-lapply(Fits,function(z)lines(dat$x,predict(z$fit),col=z$col,lty=z$col,lwd=z$col/2))
points(dat$x,dat$y,pch=19,cex=2,col=rgb(1,0,0,0.5))
aic<-unlist(lapply(Fits,FUN=function(z)z$AIC))
legend("topright",legend= paste(1:LFts,aic),text.col=1:LFts,title="n AIC",lty=1:LFts,lwd=(1:LFts/2),col=1:LFts)
par(new=T)
plot(diff(aic),type="o",axes=F,xlab="",ylab="")
@ejjunju
Copy link
Author

ejjunju commented Feb 14, 2014

Fitting and testing fit of data with polynomials.
Nice plot floows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment