Q weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE) allx nox Q source('~/meetings_workshops/Rmodeling/basicFunctions.r') debug(weightedDotPlotGroup) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE) length(xnum) table(xnum) nox Q source('~/meetings_workshops/Rmodeling/basicFunctions.r') debug(weightedDotPlotGroup) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE) table(xnum) dim(freq) nox graphy[i] nox Q source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE) debug(weightedDotPlotGroup) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE) summary(freq) head(freq) freq=table(y,x) head(freq) colSums(freq) freq=freq/mean(freq) mean(freq) freq=table(y,x) mean(freq) warnings() c source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20) ?plot ?par ?plot ?title weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.axis=.6) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.title=.6) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.title=.26) ?par weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.26) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.06) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.06) source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.06) n meany Q source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.06) source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.06) ?axis source('~/meetings_workshops/Rmodeling/basicFunctions.r') ?axis weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,cex.lab=.06) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20) source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20) ?axis source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,las=1) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='Genre',ylab='Correct',showmeans=TRUE,scale=20,las=2) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.1),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2) ?par weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,mai=c(.5,2,0,0)) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,mai=c(5,5,,0,0)) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,mai=c(5,5,0,0)) ?par weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,mai=c(5,0,0,0)) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2) source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,pin=c(3,3)) plot(1:16) plot(1:16,mai=c(5,5,0,0)) par(mai=c(5,5,0,0)) plot(1:16) source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,pin=c(3,3)) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2) source('~/meetings_workshops/Rmodeling/basicFunctions.r') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.02),xlab='',ylab='Correct',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5)) ??pdf ?pdf weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Fraction Correct',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5)) fit=lm(PctCorrect~GENRE,data=it) head(it) fit=lm(PctCorrect~GENRE..AMG.,data=it) fit coef(fit) predict(fit,data.frame(GENRE..AMG.='Blues')) predict(fit,data.frame(GENRE..AMG.=I('Blues'))) str(it) it$genre=as.factor(it$GEN) head(it) fit=lm(PctCorrect~genre,data=it) coef(fit) predict(fit,data.frame(genre='blues')) predict(fit,data.frame(genre='Blues')) predict(fit,data.frame(genre=unique(it$genre))) predict(fit,data.frame(genre=unique(it$genre)),) head(study3) predict(fit,data.frame(genre=unique(it$genre)),interval='prediction') predict(fit,data.frame(genre=unique(it$genre)),interval='confidence') pred=predict(fit,data.frame(genre=unique(it$genre)),interval='confidence') lines(pred$fit) lines(pred[,'fit']) pred=data.frame(genre=unique(it$genre)) pred rownames(pred)=pred[,1] fill=data.frame(genre=unique(it$genre)) rownames(fill)=fill[,1] pred=predict(fit,newdata=fill,interval='confidence') pred order(rownames(pred)) pred=predict(fit,newdata=fill[ord,],interval='confidence') ord=order(rownames(pred)) pred pred[ord,] pred=pred[ord,] lines(pred[,'fit']) lines(pred[,'lwr']) lines(pred[,'upr']) fit=lm(PctCorrect~GENRE,data=it) weightedDotPlot(study3$Tessitura,study3$Authority,ylim=c(1,5.5),xlim=c(1,7.5),scale=2,xlab='Tessitura',ylab='Authority',showmeans=TRUE) fit=lm(PctCorrect~GENRE,data=it) weightedDotPlotGroup(x=study3$Gender,y=study3$Authority,ylim=c(0,5.5),xlab='Gender',ylab='Auth',showmeans=TRUE) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,5.5),xlab='Gender',ylab='Auth',showmeans=TRUE) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,7.5),xlab='Gender',ylab='Auth',showmeans=TRUE) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Auth',showmeans=TRUE) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Authority',showmeans=TRUE) box() weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Authority') weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Authority',scale=2) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Authority',scale=.2) weightedDotPlotGroup(x=study3$Authority,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Authority',scale=.5) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Authority',scale=.2) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Tessitura',scale=1) box() graphics.off() weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Tessitura',scale=1) weightedDotPlotGroup(x=study3$Authority,y=study3$Tessitura,ylim=c(0,8),xlab='Authority',ylab='Tessitura',scale=1) weightedDotPlotGroup(x=study3$Authority,y=study3$Tessitura,ylim=c(0,8),xlab='Authority',ylab='Tessitura',scale=1,showmeans=TRUE) weightedDotPlot(x=study3$Authority,y=study3$Tessitura,ylim=c(0,8),xlab='Authority',ylab='Tessitura',scale=1,showmeans=TRUE) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Tessitura',scale=1) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Fraction Correct',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5)) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Fraction Correct',scale=20,las=2,marg=c(2,1,.5,.5)) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Tessitura',scale=1) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Tessitura',scale=1,showmeans) weightedDotPlotGroup(x=study3$Gender,y=study3$Tessitura,ylim=c(0,8),xlab='Gender',ylab='Tessitura',scale=1,showmeans=TRUE) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Fraction Correct',scale=20,las=2,marg=c(2,1,.5,.5)) weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Fraction Correct',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5)) head(it) plot(PctCorrect~seconds,data=it) weightedDotPlotGroup(x=it$seconds,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Length(sec)',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5)) weightedDotPlot(x=it$seconds,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Length(sec)',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5)) abline(lm(PctCorrect~seconds,data=it)) summary(lm(PctCorrect~seconds,data=it)) lm(PctCorrect~seconds+GENRE..AMG.) lm(PctCorrect~seconds+GENRE..AMG.,data=it) coef(lm(PctCorrect~seconds+GENRE..AMG.,data=it)) data.frame(coef(lm(PctCorrect~seconds+GENRE..AMG.,data=it))) data.frame(coef(lm(PctCorrect~GENRE..AMG.,data=it))) head(study3) plot(AverageHigh~AverageLow,data=MusicTempoData) abline(lm(AverageHigh~AverageLow,data=MusicTempoData)) summary(lm(AverageHigh~AverageLow,data=MusicTempoData)) fit=summary(lm(AverageHigh~AverageLow,data=MusicTempoData)) names(fit) options(width=80) names(fit) options(width=100) names(fit) fit$r.squared fit$residuals sd(fit$residuals) 2*sd(fit$residuals) plot(MusicTempoData$AverageLow,fit$res) abline(h=0) abline(h=c(3.4,-3.4)) abline(h=c(6.4,-6.4)) plot(AverageHigh~AverageLow,data=MusicTempoData) abline(lm(AverageHigh~AverageLow,data=MusicTempoData)) coef(fit) y = slope * x + intercept 67 * .97 + 20.2 fit$r.squared sqrt(fit$r.squared) var(MusicTempoData$AverageHigh) abline(h=mean(MusicTempoData$AverageHigh)) var(fit$residuals) fit=(lm(AverageHigh~AverageLow,data=MusicTempoData)) sd(fit$residuals) fitsumm=summary(lm(AverageHigh~AverageLow,data=MusicTempoData)) names(fit) names(fitsumm) fit$fitted.values names(fit) points(MusicTempoData$AverageLow,fit$fitted.values,col='red') ?predict ?predict.lm predict.lm(fit,newdata=data.frame(AverageLow=40)) data.frame(AverageLow=40) data.frame(AverageLow=35:95) emptydf=data.frame(AverageLow=35:95) head(emptydf) predict.lm(fit,newdata=emptydf) filleddf=data.frame(emptydf,predict.lm(fit,newdata=emptydf)) filleddf lines(filleddf[,1],filleddf[,2],lwd=2,col='blue') predict.lm(fit,newdata=emptydf,interval='confidence') pred=predict.lm(fit,newdata=emptydf,interval='confidence') head(pred) lines(35:95,pred$lwr) lines(35:95,pred[,'lwr']) lines(35:95,pred$upr) lines(35:95,pred[,'lw\\upr']) lines(35:95,pred[,'lwr']) lines(35:95,pred[,'upr']) pred2=predict.lm(fit,newdata=emptydf,interval='prediction') lines(35:95,pred2[,'upr'],lty='dashed') lines(35:95,pred2[,'lwr'],lty='dashed') ls() ls(fit) pred2=predict.lm(fit,newdata=emptydf,interval='prediction') pred=predict.lm(fit,newdata=emptydf,interval='confidence') weightedDotPlotGroup(x=it$GENRE,y=it$Pct,ylim=c(0,1.03),xlab='',ylab='Fraction Correct',showmeans=TRUE,scale=20,las=2,marg=c(2,1,.5,.5 summary(lm(Tessitura~Authority,data=study3)) head(study3) (lm(Tessitura~Gender,data=study3)) boxplot(Tessitura~Gender,data=study3) plot(AverageHigh~AverageLow,data=MusicTempoData) abline(lm(AverageHigh~AverageLow,data=MusicTempoData)) emptydf=data.frame(AverageLow=35:95) pred2=predict.lm(fit,newdata=emptydf,interval='prediction') pred=predict.lm(fit,newdata=emptydf,interval='confidence') lines(35:95,pred2[,'lwr'],lty='dashed') lines(35:95,pred2[,c('upr','lwr')],lty='dashed') lines(35:95,pred2[,'lwr'],lty='dashed') lines(35:95,pred2[,'upr'],lty='dashed') lines(35:95,pred[,'lwr'],lty='dashed') lines(35:95,pred[,'upr'],lty='dashed') head(study3) lm(Tessitura~Gender,data=study3) table(study3$Gender) table(study3$Gender,exclude=NULL) plot(Tessitura~Gender,data=study3) table(study3$Gender,study3$Tessitura,exclude=NULL) var(study3$Tessitura) var(study3$Tessitura,na.rm=TRUE) subset(study3,Gender=='M') var(subset(study3,Gender=='M')$Tessitura) var(subset(study3,Gender=='M')$Tessitura,na.rm=TRUE) var(study3$Tessitura,na.rm=TRUE) var(subset(study3,Gender=='M')$Tessitura,na.rm=TRUE) var(subset(study3,Gender=='F')$Tessitura,na.rm=TRUE) mean(study3$Tessitura,na.rm=TRUE) abline(h=mean(study3$Tessitura,na.rm=TRUE)) sd(study3$Tessitura,na.rm=TRUE) lm(Tessitura~Gender,data=study3) emptydf=data.frame(Gender=c('F','M')) emptydf fittess=lm(Tessitura~Gender,data=study3) emptydf=data.frame(Gender=c('F','M')) predict.lm(fittess,newdata=emptydf,interval='confidence') predict.lm(fittess,newdata=emptydf,interval='prediction') coef(fittess) summary(fittess) ls(fittess) head(study3) fit=lm(Authority~Tessitura,data=study3) summary(fit) plot(Authority~Tessitura,data=study3) plot(Authority~Tessitura,data=study3,cex=1.5) abline(fit) emptydf=data.frame(Tessitura=1:7) emptydf emptydf=data.frame(1:7) emptydf emptydf=data.frame(Tessitura=1:7) emptydf predict.lm(fit,newdata=emptydf) predict.lm(fit,newdata=emptydf,interval='confidence') lines(emptydf$Tessitura,pred[,2]) pred=predict.lm(fit,newdata=emptydf,interval='confidence') pred lines(emptydf$Tessitura,pred[,2]) lines(emptydf$Tessitura,pred[,3]) for(i in 1:3) lines(emptydf$Tessitura,pred[,2]) for(i in 1:3) lines(emptydf$Tessitura,pred[,i],col='red') pred=predict.lm(fit,newdata=emptydf,interval='prediction') for(i in 1:3) lines(emptydf$Tessitura,pred[,i],col='blue') head(study3) fit=lm(Authority~Tessitura+Age,data=study3) summary(fit) fit=lm(Authority~Tessitura,data=study3) fit2=lm(Authority~Tessitura+Age,data=study3) coef(fit) coef(fit2) Authority = 2.04 + .048*Age - .118*Tessitura table(study3$Age) summary(study3$Age) plot(Authority~Tessitura,data=study3,cex=1.5) abline(2.04,-.118) abline(4.02,-.2) abline(fit) .048*33 abline(2.04+1.58,-.118) abline(2.04+1.58,-.118,col='red') abline(2.04+.048*65,-.118,col='red') abline(2.04+.048*0,-.118,col='red') points(Authority~Tessitura,data=subset(study3,Age<25),pch=16) points(Authority~Tessitura,data=subset(study3,Age>55),pch=16,col='blue') points(Authority~Tessitura,data=subset(study3,Age<20),pch=16,col='green') abline(fit) summary(fit2) summary(study3$Age) fithigh=lm(Authority~Tessitura,data=subset(study3,Age>=42.5)) abline(fithigh,col='blue') summary(fithigh) fitlow=lm(Authority~Tessitura,data=subset(study3,Age<=25)) summary(fitlow) abline(fitlow,col='green') summary(fit2) study3457file="~/meetings_workshops/Rmodeling/data/3457.csv" x=read.delim(study3457file) head(x) str(x) table(x$Meter) table(x$Participant) table(x$Pref,exclude=NULL) table(x$Exp,exclude=NULL) head(x) as.numeric('2a') table(x$Meter) table(x$Meter,exclude=NULL) head(x) lm(Preference~Experience+Meter,data=x) lm(Preference~Meter,data=x) fit1=lm(Preference~Meter,data=x) summary(fit1)$coef plot(Preference~Meter,data=x) fit2=lm(Preference~Meter+Experience,data=x) summary(fit2)$coef names(fit1) fitMeter=lm(Preference~Meter+Experience,data=x) fit1=lm(Preference~Meter,data=x) warnings() fit1=lm(Preference~Meter,data=x) warnings() emptydf=data.frame(Meter=c('Five','Four','Three','Seven')) emptydf predict.lm(fit2,newdata=emptydf) emptydf=data.frame(Meter=c('Five','Four','Three','Seven'),Experience=c(1,1,1,1))) emptydf=data.frame(Meter=c('Five','Four','Three','Seven'),Experience=c(1,1,1,1)) emptydf predict.lm(fit2,newdata=emptydf) rep(unique(x$Meter),10) rep(unique(x$Meter),2) unique(x$Meter) rep(unique(x$Meter),2) emptydf=data.frame(Meter=rep(unique(x$Meter),2),Experience=c(1,1,1,1,5,5,5,5)) emptydf predict.lm(fit2,newdata=emptydf) fit1=lm(Preference~Meter,data=x) emptydf=data.frame(Meter='Five') emptydf predict.lm(fit1,newdata=emptydf) emptydf=data.frame(Meter=c('Five','Four','Seven')) emptydf predict.lm(fit1,newdata=emptydf) coef(fit1) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) predict.lm(fit1,newdata=emptydf) rbind(emptydf,predict.lm(fit1,newdata=emptydf)) cbind(emptydf,predict.lm(fit1,newdata=emptydf)) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf)) plot(x$Preference,x$Meter) plot(x$Meter,x$Preference) plot(x$Meter,x$Preference,xlab='Meter') plot(x$Preference,x$Meter) table(x$Preference,x$Meter) cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) emptydf predict.lm(fit1,newdata=emptydf,interval='confidence') cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) plot(x$Meter,x$Preference,xlab='Meter') coef(fit1) mean(subset(x,Meter=='Four)$Preference) ' ' mean(subset(x,Meter=='Four')$Preference) mean(subset(x,Meter=='Five')$Preference) tapply(x$Preference,x$Meter,mean) tapply(x$Preference,x$Meter,median) tapply(x$Preference,x$Meter,sd) cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) emptydf summary(fit2) fit2=lm(Preference~Meter+Experience,data=x) plot(Preference~Meter+Experience,data=x) boxplot(Preference~Meter+Experience,data=x) plot(Preference~Meter+Experience,data=x) table(x$Preference,x$Meter) table(x$Preference,x$Meter) plot(Preference~Meter,data=x) abline(v=1) abline(v=2) freq=table(x$Preference,x$Meter) freq freq[,1] points(rep(1,7),1:7,cex=freq[,1]) rep(1,7) 1:7 points(rep(1,7),1:7,cex=freq[,1]/5) plot(Preference~Meter,data=x) points(rep(1,7),1:7,cex=freq[,1]/5) for(i in 1:4) points(rep(i,7),1:7,cex=freq[,i]/5) cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) ?arrow ?arrows arrows(1,4,1,4.29) ?arrows arrows(1,4,1,4.29,length=.1,col='red',lwd=2) arrows(1,4,1,3.71,length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,1],i,pred[i,2],length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,1],i,pred[i,3],length=.1,col='red',lwd=2) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) for(i in 1:4) arrows(i,pred[i,1],i,pred[i,2],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,1],i,pred[i,3],length=.1,col='blue',lwd=2) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) pred for(i in 1:4) arrows(i,pred[i,1],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,1],i,pred[i,4],length=.1,col='blue',lwd=2) pred[i,1] for(i in 1:4) arrows(i,pred[i,2],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,4],length=.1,col='blue',lwd=2) fit2=lm(Preference~Meter+Experience,data=x) summary(fit2) plot(Preference~Meter,data=x) fit1=lm(Preference~Meter,data=x) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) freq=table(x$Preference,x$Meter) for(i in 1:4) points(rep(i,7),1:7,cex=freq[,i]/5) # arrows(1,4,1,4.29,length=.1,col='red',lwd=2) # arrows(1,4,1,3.71,length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,4],length=.1,col='blue',lwd=2) points(1:4,pred[,2],pch=16,col='blue',cex=1.5) plot(1:7,xlim=c(.5,4.5)) plot(1:7,xlim=c(.5,4.5),col='white') fit1=lm(Preference~Meter,data=x) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) freq=table(x$Preference,x$Meter) for(i in 1:4) points(rep(i,7),1:7,cex=freq[,i]/5) points(1:4,pred[,2],pch=16,col='blue',cex=1.5) # arrows(1,4,1,4.29,length=.1,col='red',lwd=2) # arrows(1,4,1,3.71,length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,4],length=.1,col='blue',lwd=2) plot(1:7,xlim=c(.5,4.5),col='white',xlab='Meter',ylab='Preference') fit1=lm(Preference~Meter,data=x) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) freq=table(x$Preference,x$Meter) for(i in 1:4) points(rep(i,7),1:7,cex=freq[,i]/5) points(1:4,pred[,2],pch=16,col='blue',cex=1.5) # arrows(1,4,1,4.29,length=.1,col='red',lwd=2) # arrows(1,4,1,3.71,length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,4],length=.1,col='blue',lwd=2) plot(1:7,xlim=c(.5,4.5),col='white',xlab='Meter',ylab='Preference',axes=FALSE) axis(1,at=1:4,labels=c('Five','Four','Seven','Three')) fit1=lm(Preference~Meter,data=x) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) freq=table(x$Preference,x$Meter) for(i in 1:4) points(rep(i,7),1:7,cex=freq[,i]/5) points(1:4,pred[,2],pch=16,col='blue',cex=1.5) # arrows(1,4,1,4.29,length=.1,col='red',lwd=2) # arrows(1,4,1,3.71,length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,4],length=.1,col='blue',lwd=2) plot(1:7,xlim=c(.5,4.5),col='white',xlab='Meter',ylab='Preference',axes=FALSE) axis(1,at=1:4,labels=c('Five','Four','Seven','Three')) axis(2) box() fit1=lm(Preference~Meter,data=x) emptydf=data.frame(Meter=c('Five','Four','Seven','Three')) pred=cbind(emptydf,pred=predict.lm(fit1,newdata=emptydf,interval='confidence')) freq=table(x$Preference,x$Meter) for(i in 1:4) points(rep(i,7),1:7,cex=freq[,i]/5) points(1:4,pred[,2],pch=16,col='blue',cex=1.5) # arrows(1,4,1,4.29,length=.1,col='red',lwd=2) # arrows(1,4,1,3.71,length=.1,col='red',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,3],length=.1,col='blue',lwd=2) for(i in 1:4) arrows(i,pred[i,2],i,pred[i,4],length=.1,col='blue',lwd=2) savehistory('~/meetings_workshops/Rmodeling/OSU/history/hist9May.txt')