################################################### # CPUReg2 Example -- Source code file cpureg2.R # ################################################### # Read and print data frame. cpu = read.table("cpu.txt", header=T) cat("CPU data frame:\n") print(cpu) # Full regression model. model1 <- lm(CpuTime ~ CardsIn + LinesOut + Steps + MountedDevices, data=cpu) cat("Full regression model:\n") print(summary(model1)) # Remove least significant regressor CardsIn. model2 <- lm(CpuTime ~ LinesOut + Steps + MountedDevices, data=cpu) cat("Regression model with CardsIn removed:\n") print(summary(model2)) # Show model with standardized regression coefficients. model3 = lm(scale(CpuTime) ~ scale(LinesOut) + scale(Steps) + scale(MountedDevices), data=cpu) cat("Regression model with CardsIn removed,\n") cat("standardized coeffcients:\n") print(summary(model3)) # Create plots. # Attach cpu data frame so its variables are available # with unqualified names for plotting. attach(cpu) p <- fitted(model2) r <- residuals(model2) pdf("cpureg2.pdf") plot(p, r, main="Residual Plot 1", xlab="Predicted Values", ylab="Residuals") abline(h=0, lty="dashed") plot(LinesOut, r, main="Residual Plot 2", xlab="Number of Lines Output", ylab="Residuals") abline(h=0, lty="dashed") plot(Steps, r, main="Residual Plot 3", xlab="Number of Programs Loaded", ylab="Residuals") abline(h=0, lty="dashed") plot(MountedDevices, r, main="Residual Plot 4", xlab="Number of Mounted Devices", ylab="Residuals") abline(h=0, lty="dashed") qqnorm(r, main="Normal Plot for Residuals", ylab="Residuals") dev.off( )