Created
February 14, 2014 15:48
-
-
Save ejjunju/9003366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fitting and testing fit of data with polynomials.
Nice plot floows