rm(list=ls()) library(KernSmooth) lmc <- read.table("lmc.txt",header=TRUE) lmc <- lmc[lmc[,3] > 0,] ## estimate density of periods using kernel density estimation summary(lmc[,3]) hist(log(lmc[,3],base=10)) plot(density(log(lmc[,3],base=10))) bw <- (10:5)/20 plot(density(log(lmc[,3],base=10))) plot(density(log(lmc[,3],base=10),bw="SJ")) ## there is so much data that bandwidth selection ## is not so important here ii <- 1 period <- lmc[ii,3] f <- paste("lmc/V/",lmc[ii,1],".dat",sep="") lc <- read.table(f) ## fold light curve and order times lc[,1] <- lc[,1] %% period lc <- lc[order(lc[,1]),] plot(lc[,1],lc[,2],ylim=rev(range(lc[,2])),xlab="Phase",ylab="Mag") segments(lc[,1],lc[,2]-lc[,3],lc[,1],lc[,2]+lc[,3],col='grey') out <- ksmooth(lc[,1],lc[,2],kernel="normal",bandwidth=0.1) points(out$x,out$y,type='l') out <- ksmooth(lc[,1],lc[,2],kernel="normal",bandwidth=0.5) points(out$x,out$y,type='l',col="blue") out <- ksmooth(lc[,1],lc[,2],kernel="normal",bandwidth=0.02) points(out$x,out$y,type='l',col="orange") ## automatic bandwidth selection from packages: locfit ## see Tutorial on Nonparametric Inference with R (available on course website) ## for information about computing confidence bands ## for nadaraya watson regression