## -----------------------------------------------------------------------------------##
## Box-Cox transformation
piat.final<-read.table('nlsy.white.age12.grade7.txt', header=T)
dim(piat.final)

## plot of data
plot(2:6, piat.final[1, 2:6], ylim=c(min(piat.final[,2:6], na.rm=T),100), type='l')

for (i in 2:194){
	lines(2:6, piat.final[i, 2:6])
	}

## data for box-cox transformation analysis
write.table(piat.final[,2:6], 'nlsy.box.cox.txt', row.names=F, quote=F)

lambda<-seq(-1, -.1, .1)
par(mfrow=c(2,3))
for (l in lambda){
	apply((piat.final[, 2:6]^l-1)/l, 2, hist)
	plot(l, l)
	text(l,l, l)
	}
	
## set 100 to be missing data?
piat.final.100<-piat.final
for (i in 2:6){
	piat.final.100[piat.final.100[,i]==100 | is.na(piat.final.100[,i]) , i]<-NA
	}

M<-is.na(piat.final.100)
apply(M, 2, sum)
## -----------------------------------------------------------------------------------##