plot(seconds~words.,data=it) colnames(it) colnames(it)[1]='excerpt' colnames(it)[4] colnames(it)[4]='words' colnames(it)[5] colnames(it)[5]='genre' colnames(it) options(width=60) colnames(it) write.table(it,file='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv',sep='\t',quote=FALSE,row.names=FALSE) fitit=lm(PctCorrect~genre+seconds,data=it) coef(it) coef(fitit) data.frame(coef(fitit)) unique(it$genre) data.frame(coef(fitit)) ls(fitit) fitit=lm(PctCorrect~words+seconds,data=it) data.frame(coef(fitit)) summary(lm(seconds~words.,data=it)) summary(fitit) head(it) success=data.frame(right=it$words,wrong=round(it$words(1-it$PctCorrect),0) ) success=data.frame(right=it$words,wrong=round(it$words*(1-it$PctCorrect),0) ) success=data.frame(right=it$words,wrong=round(it$words*(1-it$PctCorrect),0)) dim(success) head(success) head(it) fitit=glm(success~it$seconds,family=poisson(link='identity')) success=as.matrix(data.frame(right=it$words,wrong=round(it$words*(1-it$PctCorrect),0))) fitit=glm(success~it$seconds,family=poisson(link='identity')) dim(success) dim(it) head(success) good=!is.na(success$wrong) good=!is.na(success[,2]) fitit=glm(success[good,]~it$seconds[good],family=poisson(link='identity')) table(good) head(it) summary(it) it=subset(it,PctCorrect>=0) dim(it) write.table(it,file='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv',sep='\t',quote=FALSE,row.names=FALSE) success=as.matrix(data.frame(right=it$words,wrong=round(it$words*(1-it$PctCorrect),0))) dim(success) table(success[,1],success[,2]) options(width=80) table(success[,1],success[,2]) fitit=glm(success[good,]~it$seconds[good],family=poisson(link='identity')) fitit=glm(success~it$seconds,family=poisson(link='identity')) fitit=glm(success~it$seconds,family=binomial(link='logit')) summary(fitit) fitit=glm(success~it$seconds+it$genre,family=binomial(link='logit')) summary(fitit) ?predict.glm emptydb=data.frame(seconds=1,genre='Rap') predict.glm(fitit,newdata=emptydb) summary(fitit) emptydb ?predict.glm predict.glm(fitit,newdata=emptydb,type='response') ?predict.glm predict.lm(fitit,newdata=emptydb,type='response') ?predict.glm predict(fitit,newdata=emptydb,type='response') fitit=glm(success~it$seconds+it$genre,family=binomial(link='logit')) emptydb predict.glm(fitit,newdata=emptydb,type='response') ?predict.glm pred=predict.glm(fitit,type='response') str(pred) pred=cbind(it,predict.glm(fitit,type='response')) head(pred) pred=cbind(it,pred=predict.glm(fitit,type='response')) head(pred) plot(pred~seconds,data=pred) plot(pred~seconds+genre,data=pred) plot(pred~seconds,data=pred) allgen=unique(it$genre) ord=order(it$seconds) for(i in 1:length(allgen)) lines(pred~seconds,data=subset(it,genre==allgen[i])[ord,]) for(i in 1:length(allgen)) lines(pred~seconds,data=subset(pred,genre==allgen[i])[ord,]) for(i in 1:length(allgen)) lines(pred~seconds,data=subset(pred,genre==allgen[i])[ord,],col=i) ?legend legend(x='top',legend=allgen,col=1:length(allgen)) legend(x='top',legend=allgen,col=1:length(allgen),lty='solid') legend(x='top',legend=allgen,col=1:length(allgen),lty='solid',rows=1) ?legend legend(x='top',legend=allgen,col=1:length(allgen),lty='solid',ncol=length(allgen)) legend(x=6,y=1,legend=allgen,col=1:length(allgen),lty='solid',ncol=length(allgen)) plot(pred~seconds,data=pred,xlim=c(0,35)) for(i in 1:length(allgen)) lines(pred~seconds,data=subset(pred,genre==allgen[i])[ord,],col=i) legend(x='right',legend=allgen,col=1:length(allgen),lty='solid') emptydb=data.frame(seconds=1:15,genre=rep('Rap',15)) allgen=unique(it$genre) predict.glm(fitit,newdata=emptydb,type='response') str(fitit) ls(fitit) fitit$family predict(fitit,newdata=emptydb,type='response') predict(fitit,emptydb,type='response') emptydb ls(fitit) str(fitit$data) ls(fitit$data) names(fitit$data) names(fitit@data) str(fitit$data) str(fitit) str(fitit$model) emptydb str(emptydb) emptydb=data.frame(seconds=1:15,genre=I(rep('Rap',15))) str(emptydb) predict.glm(fitit,newdata=emptydb,type='response') head(it) it=read.delim(NatIntelligibilityFile) NatIntelligibilityFile='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv' it=read.delim(NatIntelligibilityFile) head(it) names(fit) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') OrigIntelligibilityFile='~/meetings_workshops/Rmodeling/data/NatDataOrig.csv' it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') dim(it) head(it) dim(it) table(is.na(it$Pct)) str(it) table(it$Pct) head(it) table(it$GEN) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') dim(it) table(it$GEN) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') dim(it) table(it$GEN) str(it) table(it$subject) table(is.na(it$Pct)) it=subset(it,PctCorrect>=0) dim(it) write.table(it,file='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv',sep='\t',quote=FALSE,row.names=FALSE) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') head(it) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') head(it) subset(it,genre='Classical') subset(it,genre=='Classical') subset(it,genre=='Classical')[,1:4] subset(it,genre=='Classical')[,1:3] subset(it,genre=='Classical')[,1:3] subset(it,genre=='Classical')[,1:3] head(subset(it,genre=='Classical')[,1:3]) head(subset(it,genre=='Classical')[,c(1,3,4,5)]) (subset(it,genre=='Classical')[,c(1,3,4,5)]) (subset(it,genre=='Classical')[,-2]) (subset(it,genre=='Classical')[,2]) it=subset(it,PctCorrect>=0) write.table(it,file='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv',sep='\t',quote=FALSE,row.names=FALSE) plot(fit) fit2=lm(Preference~Meter+Experience,data=x) head(study3) fit2=lm(Authority~Gender+Age,data=study3) summary(fit)$coef summary(fit2)$coef fit2=lm(Authority~Gender+Age,data=study3) summary(fit2)$coef plot(Authority~Age,data=study3) graphics.off() plot(Authority~Age,data=study3) fit=lm(Authority~Age,data=study3) abline(fit) summary(fit)$coef abline(1.25,.055,col='red') summary(fit2)$coef abline(1.07,.0516,col='pink') abline(1.61,.0516,col='blue') predict.lm(fit2,newdata=data.frame(Gender=c('M','F'),Age=c(20,20)) ) predict.lm(fit2,newdata=data.frame(Gender=c('M','F'),Age=c(20,20))) predict.lm(fit2,newdata=data.frame(Gender=c('M','F'),Age=c(40,40))) dev.open() x11() plot(Authority~Age,data=study3) abline(fit) dev.set(2) plot(Authority~Age,data=study3) abline(1.61,.0516,col='blue') abline(1.07,.0516,col='pink') par(mfcol=c(2,1)) plot(Authority~Age,data=study3) plot(Authority~Age,data=study3) plot(Authority~Age,data=study3) abline(fit) plot(Authority~Age,data=study3) abline(1.07,.0516,col='pink') abline(1.61,.0516,col='blue') fitM=lm(Authority~Age,data=subset(study3,Gender=='M') ) fitM=lm(Authority~Age,data=subset(study3,Gender=='M')) plot(Authority~Age,data=study3) abline(1.61,.0516,col='blue') abline(1.07,.0516,col='pink') x11() dev.set(2) plot(Authority~Age,data=study3) abline(fit) fitM=lm(Authority~Age,data=subset(study3,Gender=='M')) fitF=lm(Authority~Age,data=subset(study3,Gender=='F')) x<-3 x abline(fitM,col='blue',lty='dashed') abline(fitF,col='red',lty='dashed') dev.set(3) abline(fitM,col='blue',lty='dashed') abline(fitF,col='red',lty='dashed') summary(fitM)$coef summary(fitF)$coef) summary(fitF)$coef summary(fitM)$coef points(Authority~Age,data=subset(study3,Gender=='M'),col='red',pch=16,cex=.8) points(Authority~Age,data=subset(study3,Gender=='M'),col='blue',pch=1,cex=1.3) points(Authority~Age,data=subset(study3,Gender=='F'),col='red',pch=16,cex=.8) it=read.delim(NatIntelligibilityFile) NatIntelligibilityFile='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv' it=read.delim(NatIntelligibilityFile) head(it) str(it) table(it$subject) NatIntelligibilityFile='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv' it=read.delim(NatIntelligibilityFile) table(it$subject) table(it$genre) table(it$genre,it$subject) dim(it) ?read.table head(it) it$genre[1] it$genre[1]=='Avant-garde' it$genre[1]==1 str(it) dim(it) it=read.delim('~/Desktop/NatDataCorr.csv') dim(it) tail(it) it=read.delim('~/Desktop/NatDataCorr.csv') dim(it) table(it$subject) str(it) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') dim(it) it=subset(it,PctCorrect>=0) head(it) colnames(it) dim(it) table(it$subject) itcorr=read.delim('~/Desktop/NatDataCorr.csv') dim(itcorr) missing=which(!it$excerpt %in% itcorr$excerpt) table(missing) it[197,] it[197,-2] length(unique(it$excerpt)) length(unique(itcorr$excerpt)) plot(it$Pct[1:top],itcorr$Pct[1:top]) top=50 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=500 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=100 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=300 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=200 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=180 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=150 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=165 plot(it$Pct[1:top],itcorr$Pct[1:top]) top=155 plot(it$Pct[1:top],itcorr$Pct[1:top]) it[150:160,-2] itcorr[150:160,-2] write.table(it,file='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv',sep='\t',quote=FALSE,row.names=FALSE) itagain=read.delim(NatIntelligibilityFile) dim(itagain) dim(it) write.table(it[,-2],file='~/meetings_workshops/Rmodeling/data/NatDataCorr.csv',sep='\t',quote=FALSE,row.names=FALSE) itagain=read.delim(NatIntelligibilityFile) dim(it) table(it$LYR) length(table(it$LYR)) itagain=read.delim(NatIntelligibilityFile,quote="'") dim(itagain) ?read.delim grep("'",itagain$LYR) grep("'",itagain$LYR,fixed=TRUE) itagain=read.delim(NatIntelligibilityFile,quote="") dim(itagain) head(itagain) itagain=read.delim(NatIntelligibilityFile) head(itagain) dim(itagain) it=toSingleColumn(infile=OrigIntelligibilityFile,basecol=1:6,responsecol=7:36,resultname='PctCorrect') head(it) dim(it) it=subset(it,PctCorrect>=0) dim(it) grep("'",it$LYR,fixed=TRUE) grep("'",it$LYR) length(grep("'",it$LYR)) length(grep('"',it$LYR)) subset(it,logical.grep('"',it$LYR)) subset(it,logical.grep('"',it$LYR))[2] subset(it,logical.grep("'",it$LYR))[2] unique(subset(it,logical.grep("'",it$LYR))[2]) length(unique(subset(it,logical.grep("'",it$LYR))[2])) length(unique(subset(it,logical.grep("'",it$LYR))[,2])) (unique(subset(it,logical.grep("'",it$LYR))[,2])) dim(it) mod=lmer(PctCorrect~seconds+genre+(seconds+genre|subject),verbose=TRUE) library(lme4) mod=lmer(PctCorrect~seconds+genre+(seconds+genre|subject),verbose=TRUE) mod=lmer(PctCorrect~seconds+genre+(seconds+genre|subject),verbose=TRUE,data=it) head(x) dim(x) x=read.delim(study3457file) dim(x) head(x) table(x$Part) mod=lmer(Preference~Meter+(Meter|Participant),data=x,verbose=TRUE) display(mod) library(arm) display(mod) coef(mod) table(it$genre) modit1=lmer(PctCorrect~genre+(genre|subject),verbose=TRUE,data=it) modit1=lmer(PctCorrect~seconds+(seconds|genre),verbose=TRUE,data=it) display(modit) library(arm) display(modit) display(modit1) coef(modit1) display(modit1,digits=5) mod=lmer(Preference~Meter+(Meter|Participant),data=x,verbose=TRUE) mod=lmer(Preference~Meter+(Meter|Participant),data=x) coef(mod) fixef(mod) modlm=lm(Preference~Meter+Participant,data=x) coef(modlm) str(x) x=$Participant=as.factor(x$Participant) x$Participant=as.factor(x$Participant) str(x) modlm=lm(Preference~Meter+Participant,data=x) coef(modlm) fitit=lm(PctSuccess~seconds+genre,data=it) fitit=lm(PctCorrect~seconds+genre,data=it) colnames(it) coef(fitit) coef(fitit) options(width=60) coef(fitit) allgenre=unique(it$genre) allgenre strsplit('abc,defgh,i3',split=',') strsplit(c('abc,defgh,i3','123,45',split=',') ) strsplit(c('abc,defgh,i3','123,45'),split=',') lst=strsplit(c('abc,defgh,i3','123,45'),split=',') lst lst=strsplit(c('abc,defgh,i3','123,45'),split='') lst allgenre plot(PctCorrect~seconds+genre,data=it) graphics.off() plot(PctCorrect~seconds+genre,data=it) plot(PctCorrect~seconds+genre,data=it) plot(PctCorrect~seconds,data=it) ?axis plot(PctCorrect~seconds,data=it,axes=FALSE) axis(1,hadj=90) axis(1,hadj=0) axis(1,padj=0) axis(1,padj=90) axis(1,padj=1) ?par axis(1,las=3) plot(PctCorrect~seconds,data=it,axes=FALSE) axis(1,las=3) plot(PctCorrect~seconds,data=it,las=3) data.frame(coef(fitit)) rep(1:2,c(2,15)) c(rep(1,15),rep(20,15)) rep(c(1,20),c(15,15)) fitit=lm(PctCorrect~seconds+genre,data=it) fitit=lm(PctCorrect~seconds+genre,data=it) strsplit('abc,defgh,i3',split=',') it=read.delim(NatIntelligibilityFile) plot(PctCorrect~seconds,data=it,las=3) allgenre=unique(it$genre) emptydf=data.frame(genre=allgenre,seconds=rep(c(1,20),c(13,13))) emptydf=data.frame(genre=allgenre,seconds=rep(1,13)) pred1=predict.lm(fitit,newdata=emptydf) emptydf=data.frame(genre=allgenre,seconds=rep(15,13)) pred2=predict.lm(fitit,newdata=emptydf) pred=data.frame(pred1,pred2) rownames(pred)=allgenreemptydf=data.frame(genre=allgenre,seconds=rep(1,13)) pred1=predict.lm(fitit,newdata=emptydf) emptydf=data.frame(genre=allgenre,seconds=rep(15,13)) pred2=predict.lm(fitit,newdata=emptydf) pred=data.frame(pred1,pred2) rownames(pred)=allgenre emptydf=data.frame(genre=allgenre,seconds=rep(1,13)) emptydf pred1=predict.lm(fitit,newdata=emptydf) str(it) fitit=lm(PctCorrect~seconds+genre,data=it) str(emptydf) plot(1:2,xlim=c(1,12),ylim=c(0,1)) plot(-1,xlim=c(0,12),ylim=c(0,1)) table(it$genre,it$PctCorrect) t=table(it$genre,it$PctCorrect) y=as.numeric(colnames(t)) length(y) points(x=rep(1,length(y)),y=y,cex=t[1,]) points(x=rep(1,length(y)),y=y,cex=t[1,]/10) plot(-1,xlim=c(0,12),ylim=c(0,1)) points(x=rep(1,length(y)),y=y,cex=t[1,]/10) for(i in 1:12) points(x=rep(i,length(y)),y=y,cex=t[i,]/10) rep(1,length(y)) plot(-1,xlim=c(0,12),ylim=c(0,1)) for(i in 1:12) points(x=rep(i,length(y)),y=y,cex=t[i,]/20) plot(-1,xlim=c(0,12),ylim=c(0,1)) for(i in 1:12) points(x=rep(i,length(y)),y=y,cex=log(t[i,]+1)) plot(-1,xlim=c(0,12),ylim=c(0,1)) for(i in 1:12) points(x=rep(i,length(y)),y=y,cex=t[i,]/20) for(i in 1:12) points(rep(i,length(y)),y,cex=t[i,]/20) mod=lmer(PctCorrect~seconds,data=it) mod=lmer(PctCorrect~seconds,data=it) mod=lmer(PctCorrect~seconds+(seconds|genre),data=it) coef(mod) fit=lm(PctCorrect~seconds,data=it) coef(fit) plot(PctCorrect~seconds,data=it,las=3) abline(fit) cf=coef(mod)$genre str(cf) cf[1,] cf=as.matrix(coef(mod)$genre) coef(mod)$genre for(i in 1:13) abline(cf[i,]) mod2=lmer(PctCorrect~1+(1|genre)+(1|subject),data=it) coef(mod2)$genre coef(mod2)$subject mod3=lmer(PctCorrect~seconds+(seconds|genre)+(seconds|subject),data=it) coef(mod3)$genre coef(mod)$genre coef(mod3)$subject cf3=as.matrix(coef(mod3)$genre) mod3=lmer(PctCorrect~seconds+(seconds|genre)+(seconds|subject),data=it) for(i in 1:13) abline(cf3[i,],col=i) for(i in 1:13) abline(cf[i,],col=i) for(i in 1:13) abline(cf[i,],col=i,lty='dashed') for(i in 1:13) abline(cf[i,],col=i) for(i in 1:13) abline(cf3[i,],col=i,lty='dashed') mod2=lmer(PctCorrect~1+(1|genre)+(1|subject)+(1|excerpt),data=it) coef(mod2)$genre mod4=lmer(PctCorrect~1+(1|genre)+(1|subject)+(1|excerpt),data=it) mod2=lmer(PctCorrect~1+(1|genre)+(1|subject),data=it) coef(mod2)$genre coef(mod4)$genre se.coef(mod4)$genre se.coef(mod2)$genre mod5=lmer(PctCorrect~genre+(genre|subject)+(genre|excerpt),data=it) mod5=lmer(PctCorrect~genre+(genre|subject)+(genre|excerpt),data=it,verbose=TRUE) hist(study3$Tessitura) hist(study3$Tessitura,breaks=7) hist(study3$Authority,breaks=7) x=runif(100,min=1,max=7 ) x=runif(100,min=1,max=7) y=2*x + run(100,min=(-3),max=3) y=2*x + runif(100,min=(-3),max=3) plot(x,y) hist(x) hist(y) y=.2*x + runif(100,min=(-3),max=3) hist(y) lm(y~x) y=.2*x + runif(100,min=(-3),max=3) lm(y~x) y=.2*x + runif(100,min=(-3),max=3) lm(y~x) y=.2*x + runif(100,min=(-3),max=3) lm(y~x) x=c(rep(1,50),rep(7,50)) y=.2*x + runif(100,min=(-3),max=3) x=c(rep(1,50),rep(7,50)) y=.2*x + runif(100,min=(-3),max=3) lm(y~x) y=.2*x + runif(100,min=(-3),max=3) lm(y~x) savehistory('~/meetings_workshops/Rmodeling/OSU/history/hist10May.txt')