cat1 <- as.numeric(par1) cat2<- as.numeric(par2) intercept<-as.logical(par3) x <- t(x) xdf<-data.frame(t(y)) (V1<-dimnames(y)[[1]][cat1]) (V2<-dimnames(y)[[1]][cat2]) xdf <- data.frame(xdf[[cat1]], xdf[[cat2]]) names(xdf)<-c('Y', 'X') if(intercept == FALSE) (lmxdf<-lm(Y~ X - 1, data = xdf) ) else (lmxdf<-lm(Y~ X, data = xdf) ) sumlmxdf<-summary(lmxdf) (aov.xdf<-aov(lmxdf) ) (anova.xdf<-anova(lmxdf) ) load(file='createtable') a<-table.start() nc <- ncol(sumlmxdf$'coefficients') nr <- nrow(sumlmxdf$'coefficients') a<-table.row.start(a) a<-table.element(a,'Linear Regression Model', nc+1,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, lmxdf$call['formula'],nc+1) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, 'coefficients:',1,TRUE) a<-table.element(a, ' ',nc,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, ' ',1,TRUE) for(i in 1 : nc){ a<-table.element(a, dimnames(sumlmxdf$'coefficients')[[2]][i],1,TRUE) }#end header a<-table.row.end(a) for(i in 1: nr){ a<-table.element(a,dimnames(sumlmxdf$'coefficients')[[1]][i] ,1,TRUE) for(j in 1 : nc){ a<-table.element(a, round(sumlmxdf$coefficients[i, j], digits=3), 1 ,FALSE) } a<-table.row.end(a) } a<-table.row.start(a) a<-table.element(a, '- - - ',1,TRUE) a<-table.element(a, ' ',nc,FALSE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, 'Residual Std. Err. ',1,TRUE) a<-table.element(a, paste(round(sumlmxdf$'sigma', digits=3), ' on ', sumlmxdf$'df'[2], 'df') ,nc, FALSE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, 'Multiple R-sq. ',1,TRUE) a<-table.element(a, round(sumlmxdf$'r.squared', digits=3) ,nc, FALSE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, 'Adjusted R-sq. ',1,TRUE) a<-table.element(a, round(sumlmxdf$'adj.r.squared', digits=3) ,nc, FALSE) a<-table.row.end(a) a<-table.end(a) table.save(a,file='mytable.tab') a<-table.start() a<-table.row.start(a) a<-table.element(a,'ANOVA Statistics', 5+1,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, ' ',1,TRUE) a<-table.element(a, 'Df',1,TRUE) a<-table.element(a, 'Sum Sq',1,TRUE) a<-table.element(a, 'Mean Sq',1,TRUE) a<-table.element(a, 'F value',1,TRUE) a<-table.element(a, 'Pr(>F)',1,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, V2,1,TRUE) a<-table.element(a, anova.xdf$Df[1]) a<-table.element(a, round(anova.xdf$'Sum Sq'[1], digits=3)) a<-table.element(a, round(anova.xdf$'Mean Sq'[1], digits=3)) a<-table.element(a, round(anova.xdf$'F value'[1], digits=3)) a<-table.element(a, round(anova.xdf$'Pr(>F)'[1], digits=3)) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a, 'Residuals',1,TRUE) a<-table.element(a, anova.xdf$Df[2]) a<-table.element(a, round(anova.xdf$'Sum Sq'[2], digits=3)) a<-table.element(a, round(anova.xdf$'Mean Sq'[2], digits=3)) a<-table.element(a, ' ') a<-table.element(a, ' ') a<-table.row.end(a) a<-table.end(a) table.save(a,file='mytable1.tab') bitmap(file='regressionplot.png') plot(Y~ X, data=xdf, xlab=V2, ylab=V1, main='Regression Solution') if(intercept == TRUE) abline(coef(lmxdf), col='red') if(intercept == FALSE) abline(0.0, coef(lmxdf), col='red') dev.off() library(car) bitmap(file='residualsQQplot.png') qq.plot(resid(lmxdf), main='QQplot of Residuals of Fit') dev.off() bitmap(file='residualsplot.png') plot(xdf$X, resid(lmxdf), main='Scatterplot of Residuals of Model Fit') dev.off() bitmap(file='cooksDistanceLmplot.png') plot.lm(lmxdf, which=4) dev.off()
|