read.delim(study1file) ?read.table read.table(study1file) read.delim(study1file) ?read.table study1file="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" system('ls') system('ls -lt') study1file study1file="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" ?read.table read.table("~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv")  read.delim("~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv") MusicalTempoData=read.delim("~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv") x=read.delim("~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv") str(x) MusicTempoData=read.delim(study1file) str(MusicalTempoData) ?read.delim MusicTempoData=read.delim(study1file,row.names=1) str(MusicalTempoData) str(MusicTempoData) MusicTempoData=read.delim(study1file,row.names=1) MusicTempoData=read.delim(study1file,row.names=1) MusicTempoData=read.delim(study1file,row.names=1) str(MusicTempoData) MusicTempoData MusicTempoData['Chicago',] MusicTempoData['Chicago',]$PopDensity MusicTempoData['Chicago',2] MusicTempoData[1:5,2] MusicTempoData[,2] mean(MusicTempoData[,2]) mean(MusicTempoData[,'PopDensity']) mean(MusicTempoData$PopDensity) colMeans(MusicTempoData) str(MusicTempoData) MusicTempoData=read.delim(study1file) str(MusicTempoData) colMeans(MusicTempoData) MusicTempoData[,-1] MusicTempoData[,-(1:2)] colMeans(MusicTempoData[,-1]) ?source study1file="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" study3file="~/meetings_workshops/Rmodeling/data/study3Opera.csv" # Once you have set the working directory, you do not need the full path: study1file="studyDataOneClean.csv" study3file="study3Opera.csv" NatIntelligibilityFile='~/meetings_workshops/Rmodeling/data/Nat Data.csv' read.delim(study1file) read.table(study1file,sep='\t',header=TRUE) read.csv(study3file) MusicTempoData=read.delim(study1file,row.names=1) mean(MusicTempoData$PopDensity) colmeans(MusicTempoData) colmeans(MusicTempoData[,-1]) getwd() source('~/meetings_workshops/Rmodeling/Rbasics.r') head(MusicTempoData) head(MusicTempoData,11) plot(AverageHigh~AverageLow,data=MusicTempoData) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) MusicTempoData$AverageHigh MusicTempoData$AverageLow source('~/meetings_workshops/Rmodeling/Rbasics.r') source('~/meetings_workshops/Rmodeling/Rbasics.r') MusicTempoData$Size=MusicTempoData$Population/MusicTempoData$PopDensity MusicTempoData$Population/MusicTempoData$PopDensity MusicTempoData$Size=MusicTempoData$Population/MusicTempoData$PopDensity head(MusicTempoData,11) mean(MusicTempoData) mean(MusicTempoData$Tempo,MusicTempoData$PopDensity) mean(c(MusicTempoData$Tempo,MusicTempoData$PopDensity)) c(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) c(1,3,5) MusicTempoData[,4:5] rowMeans(MusicTempoData[,4:5]) study1file study3file ?apply ?options options('digits') options(digits=12) colmeans(MusicTempoData[,-1]) colMeans(MusicTempoData[,-1]) colMeans(MusicTempoDatA) colMeans(MusicTempoData) ?options options(max.print=10000000) colMeans(MusicTempoData) options(digits=7) colMeans(MusicTempoData) apply(MusicTempoData,2,sd) ?apply mapply(MusicTempoData,sd) mapply(sd,MusicTempoData) mapply(mean,MusicTempoData) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) identify(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,rownames(MusicTempoData)) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=rownames(MusicTempoData)) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,xlab='High Temperature (F)',ylab='Low Temperature (F)') x=c(1,2) x=c(First=1,Second=2) x names(x) y=c(First=1,Second=2) x y rbind(x,y) source('~/meetings_workshops/Rmodeling/Rbasics.r') source('~/meetings_workshops/Rmodeling/Rbasics.r') subset(study2,Gender=='M') plot(tessitura~Age,data=subset(study2,Gender=='M')) plot(tessitura~Age,data=subset(study2,Gender=='M'),col='blue') points(tessitura~Age,data=subset(study2,Gender=='F'),col='red') plot(1:16,pch=1:16) plot(1:32,pch=1:32) ?install ?install.packages ?mapply ?mapply save.history('~/meetings_workshops/Rmodeling/OSU/history/7May.txt') savehistory('~/meetings_workshops/Rmodeling/OSU/history/7May.txt') savehistory('~/meetings_workshops/Rmodeling/OSU/history/hist7May.txt') ls() ?write.table MusicTempoData save(MusicTempoData,file='MusicTempoData.rdata') rm(MusicTempoData) MusicTempoData attach(file='MusicTempoData.rdata') attach('MusicTempoData.rdata') ?attach attach(what='MusicTempoData.rdata') search() options(width=100) search() ls(2) attach(what='MusicTempoData.rdata') ls(2) ls(3) ls(34) ls(4) ls(2) ls(1) ls(2) detach(4) detach(2) search() ls(2) ?load load(file='MusicTempoData.rdata') ls() ls(2) detach(2) search() save(MusicTempoData,study1file,study3file,file='MusicTempoData.rdata') attach(what='MusicTempoData.rdata') search() ls(2) rm(study1file) rm(study3file) rm(MusicTempoData) detach(2) study1file search() attach(what='MusicTempoData.rdata') ls(2) study1file study1file head(MusicTempoData) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=16) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=3) plot(1:25,pch=1:25) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1:25) dim(MusicTempoData) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1:35) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=3) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1,cex=1.5) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=16) points(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1,cex=1.5,col='red') stpop=MusicTempoData$Population/mean(MusicTempoData$Population) stpop plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=16,cex=stpop) identify(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,rownames(MusicTempoData)) mean(MusicTempoData$Population) plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=16,cex=stpop,type='l') plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,col='red',type='l') plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,lwd=3,type='l') ?plot plot(y=MusicTempoData$AverageHigh,x=MusicTempoData$AverageLow,lwd=3,type='l') plot(y=MusicTempoData$AverageHigh,x=MusicTempoData$AverageLow,lwd=3,lty='dotted',type='l') points(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1,cex=1.5,col='red') plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,lwd=3,type='l') points(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1,cex=1.5,col='red') plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) lines(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1,cex=1.5,col='red') plot(MusicTempoData$AverageHigh,MusicTempoData$AverageLow) lines(MusicTempoData$AverageHigh,MusicTempoData$AverageLow,pch=1,cex=1.5,col='red') head(MusicTempoData) MusicTempoData$Population options(width=80) MusicTempoData$Population sort(MusicTempoData$Population) order(MusicTempoData$Population) ord=order(MusicTempoData$Population) MusicTempoData$Population[ord] ord data.frame(MusicTempoData$Population,ord) data.frame(MusicTempoData,ord) MusicTempoData$Population[ord] MusicTempoData[ord,] MusicTempoData[order(MusicTempoData$Population),] MusicTempoData[1:3,] MusicTempoData[4,] MusicTempoData[3:1,] MusicTempoData[34,] MusicTempoData[34,] ord MusicTempoData[c(34,28),] MusicTempoData[c(34,28,24),] MusicTempoData[1:3,] MusicTempoData[c(1,1,1),] MusicTempoData[c(1,1),] MusicTempoData[order(MusicTempoData$Population),] sorteddata=MusicTempoData[order(MusicTempoData$Population),] MusicTempoData$Tempo[ord] plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop) lines(AverageHigh~AverageLow,data=MusicTempoData[order(MusicTempoData$Population),]) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop) lines(AverageHigh~AverageLow,data=MusicTempoData[order(MusicTempoData$AverageLow),]) MusicTempoData[order(MusicTempoData$AverageLow),] study3=read.delim(study3file) head(study3) study3=read.csv(study3file) head(study3) plot(Tessitura~Authority,data=study3) dim(study3) runif(112,0,.1) jigger=runif(112,0,.2) plot(Tessitura+jigger~Authority,data=study3) plot(Tessitura+jigger1~Authority+jigger2,data=study3) jigger1=runif(112,0,.2) jigger2=runif(112,0,.2) plot(Tessitura+jigger1~Authority+jigger2,data=study3) par('ask' ) plot(study3$Tessitura+jigger1~study3$Authority+jigger2) par(ask=FALSE) plot(study3$Tessitura+jigger1~study3$Authority+jigger2) head(study3) graphics.off() length(jigger1) length(jigger2) plot(study3$Tessitura+jigger1~study3$Authority+jigger2) summary(jigger2) plot(study3$Tessitura+jigger1,study3$Authority+jigger2) graphics.off() plot(study3$Tessitura+jigger1,study3$Authority+jigger2) points(study3$Tessitura,study3$Authority,pch=16,cex=1.3) jigger2=runif(112,-.1,.1) jigger1=runif(112,-.1,.1) plot(study3$Tessitura,study3$Authority,pch=16,cex=1.3) points(study3$Tessitura+jigger1,study3$Authority+jigger2) points(study3$Tessitura+jigger1,study3$Authority+jigger2,pch=16,cex=.7) plot(study3$Tessitura,study3$Authority,pch=16,cex=1.3) points(study3$Tessitura+jigger1,study3$Authority+jigger2,pch=16,cex=.7) points(study3$Tessitura+jigger1,study3$Authority+jigger2,pch=16,cex=.7,col='gray') points(study3$Tessitura+jigger1,study3$Authority+jigger2,pch=16,cex=.7,col='red') plot(study3$Tessitura,study3$Authority,pch=1,cex=1.3) points(study3$Tessitura+jigger1,study3$Authority+jigger2,pch=16) runif(10,min=0,max=10) runif(5,min=0,max=10) runif(5,min=0,max=10) runif(5,min=0,max=10) runif(5,min=0,max=10) plot(study3$Tessitura,study3$Authority,pch=1,cex=1.3) points(study3$Tessitura+jigger1,study3$Authority+jigger2,pch=16) plot(study3$Tessitura,study3$Authority,pch=1,cex=1.3) points(study3$Tessitura+jigger1,study3$Authority+jigger1,pch=16) table(study3$Tessitura,study3$Authority) table(study3$Tessitura) table(study3$Authority) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE) box() plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE) axis(1) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE) ?axis axis(1,pos=60) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE,ylim=c(0,100)) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,ylim=c(0,100)) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE,ylim=c(0,100)) axis(1,pos=0) axis(2,pos=50) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE,ylim=c(0,100)) axis(1,pos=40) ?axis plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE,ylim=c(0,100)) axis(1,pos=40,at=c(50,70),labels=c('Fifty','Seventy')) box() text(50,70,'the average city') ?text text(50:55,70:75,'the average city') text(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,rownames(MusicTempoData)) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop,axes=FALSE) text(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,rownames(MusicTempoData)) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,axes=FALSE,ylim=c(0,100)) axis(1,pos=40,at=c(30,70),labels=c('Thirty','Seventy')) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,axes=FALSE,ylim=c(0,100)) axis(1,pos=40,at=c(40,60),labels=c('Forty','Sixty')) text(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,rownames(MusicTempoData)) axis(3,pos=60,at=c(40,60),labels=c('Forty','Sixty')) ?text plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,axes=FALSE,ylim=c(0,100)) axis(1,pos=40,at=c(40,60),labels=c('Forty','Sixty')) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,axes=FALSE) axis(1,pos=40,at=c(40,60),labels=c('Forty','Sixty')) text(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,rownames(MusicTempoData),cex=.5) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,axes=FALSE) text(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,rownames(MusicTempoData),cex=.75) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=0,axes=FALSE) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=1,col='white',axes=FALSE) text(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,rownames(MusicTempoData),cex=.75) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16,cex=stpop) plot(MusicTempoData$AverageLow,MusicTempoData$AverageHigh,pch=16) ?lm plot(AverageHigh~AverageLow,data=MusicTempoData) lm(AverageHigh~AverageLow,data=MusicTempoData) fit=lm(AverageHigh~AverageLow,data=MusicTempoData) summary(fit) summary(lm(AverageHigh~AverageLow,data=MusicTempoData)) fit=lm(AverageHigh~AverageLow,data=MusicTempoData) coef(fit) fit$coef summary(fit) sumfit=summary(fit) names(sumfit) summary(fit)$coefficients summary(fit)$r.squared summary(lm(AverageHigh~AverageLow,data=MusicTempoData))$r.squared summary(lm(AverageHigh~AverageLow,data=MusicTempoData))$coefficients[,4] summary(lm(AverageHigh~AverageLow,data=MusicTempoData))$coefficients[2,4] summary(lm(AverageHigh~AverageLow,data=MusicTempoData))$coefficients[2,1] abline(fit) abline(h=70) summary(lm(AverageHigh~AverageLow,data=MusicTempoData)) abline(lm(AverageHigh~AverageLow,data=MusicTempoData)) text(40,80,summary(fit)$r.squared) text(40,80,round(summary(fit)$r.squared,2)) plot(AverageHigh~AverageLow,data=MusicTempoData) abline(lm(AverageHigh~AverageLow,data=MusicTempoData)) text(40,80,round(summary(fit)$r.squared,2)) paste('a','b') text(40,80,paste('R sq.=',round(summary(fit)$r.squared,2))) plot(AverageHigh~AverageLow,data=MusicTempoData) text(40,80,round(summary(fit)$r.squared,2)) plot(AverageHigh~AverageLow,data=MusicTempoData) text(40,80,round(summary(fit)$r.squared,2)) plot(AverageHigh~AverageLow,data=MusicTempoData) text(40,80,paste('R sq.=',round(summary(fit)$r.squared,2))) abline(lm(AverageHigh~AverageLow,data=MusicTempoData)) datafile="~/meetings_workshops/Rmodeling/data/study3Opera.csv" datatable=read.csv(datafile) dim(datatable) str(datatable) datafile="studyDataOneClean.csv" datatbl=read.delim(datafile,row.names=1) datafile="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" datatbl=read.delim(datafile,row.names=1) dim(datatbl) head(datatbl) datafile="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" datatbl=read.delim(datafile,row.names=1) # Calculate some summary statistics cmeans=colMeans(datafile) # Graph 2 columns plot(datafile[,2],datafile[,1],pch=16) # Fit a regression and add the line of best fit fit=lm(datafile[,1]~datafile[,2]) abline(fit) # Show results print(cmeans) print(summary$fit) cmeans=colMeans(datatbl) # Graph 2 columns plot(datatbl[,2],datatbl[,1],pch=16) # Fit a regression and add the line of best fit fit=lm(datatbl[,1]~datatbl[,2]) abline(fit) # Show results print(cmeans) print(summary$fit) print(cmeans) print(summary(fit)) ?lm source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow lm graphWorkFlow args(graphWorkFlow) args(lm) rm(graphWorkFlow) args(graphWorkFlow) source('~/meetings_workshops/Rmodeling/basicRFunction.r') args(graphWorkFlow) graphWorkFlow() graphWorkFlow() source('~/meetings_workshops/Rmodeling/basicRFunction.r') source('~/meetings_workshops/Rmodeling/basicRFunction.r') source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow() graphWorkFlow=function() { datafile="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" datatbl=read.delim(datafile,row.names=1) # Calculate some summary statistics cmeans=colMeans(datatbl) # Graph 2 columns plot(datatbl[,2],datatbl[,1],pch=16) # Fit a regression and add the line of best fit fit=lm(datatbl[,1]~datatbl[,2]) abline(fit) # Show results print(cmeans) print(summary(fit)$coef) print(summary(fit)$r.squared) } squared=function(x) { print(x^2) } squared squared(4) squared=function(x) { y=x^2 print(y) } squared squared(4)  study1file="~/meetings_workshops/Rmodeling/data/studyDataOneClean.csv" studyfile study1file # Calculate some summary statistics source('~/meetings_workshops/Rmodeling/basicRFunction.r') args(graphWorkFlow) args(graphWorkFlow) graphWorkFlow() graphWorkFlow(study1file) source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow(study1file) source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow(study1file) print(datafile) rm(datafile) source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow(study1file) print(datafile) graphWorkFlow source('~/meetings_workshops/Rmodeling/basicRFunction.r') args(graphWorkFlow) graphWorkFlow(study1file) graphWorkFlow(study1file,2,1) graphWorkFlow(datafile=study1file,xcol=2,ycol=1) graphWorkFlow(datafile=study1file,xcol=1,ycol=2) rm(fit) source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow(datafile=study1file,xcol=1,ycol=2) source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow(datafile=study1file,xcol=1,ycol=2) graphWorkFlow(datafile=study1file,xcol=1,ycol=2) summary(fit) source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphWorkFlow(datafile=study1file,xcol=1,ycol=2) graphResult=graphWorkFlow(datafile=study1file,xcol=1,ycol=2) graphResult graphResult$coef datafile graphResult=graphWorkFlow() datafile=study3file graphResult=graphWorkFlow() datafile source('~/meetings_workshops/Rmodeling/basicRFunction.r') graphResult=graphWorkFlow(datafile=study1file) graphWorkFlow(datafile=study1file) graphWorkFlow(datafile=study1file,xcol=3,ycol=4) args(lm) head(study3) cor(study3[,-1]) study3 cor(study3[,-1],na.rm=TRUE) ?cor cor(study3[,-1],use='complete') plot(study3[,-1]) fit=lm(AverageHigh~AverageLow,data=MusicTempoData) names(summary(fit)) plot(AverageHigh~AverageLow,data=MusicTempoData,log='x') plot(AverageHigh~AverageLow,data=MusicTempoData,log='xy') plot(AverageHigh~AverageLow,data=MusicTempoData,log='y') names(summary(fit)) (summary(fit)$sigma) (summary(fit)$terms) names(summary(fit)) layout(matrix(1:2)) savehistory('~/meetings_workshops/Rmodeling/OSU/history/hist8May.txt')