Task 1

Load required library for diagnostics

library(car)

Load the data

dia <- read.table(“diamonds.txt”, header = TRUE)

Attach the data

attach(dia)

Fit the simple linear regression model

model1 <- lm(Price ~ Size)

Summary of the model (to comment on fit, R-squared, p-values, etc.)

summary(model1)

Diagnostic plots

plot(model1) # Generates 4 diagnostic plots: Residuals vs Fitted, Normal Q-Q, Scale-Location, Residuals vs Leverage

Additional diagnostics from car package

qqPlot(model1, main = “Q-Q Plot”) # Better Q-Q plot durbinWatsonTest(model1) # Test for autocorrelation ncvTest(model1) # Test for non-constant variance Chu (1996) discusses the development of a regression model to predict the price of diamond rings from the size of their diamond stones (in terms of their weight in carats). Data on both variables were obtained from a full page advertisement placed in the Straits Times newspaper by a Singapore-based retailer of diamond jewelry. Only rings made with 20 carat gold and mounted with a single diamond stone were included in the data set.

The data are available in the file diamonds.txt (See Canvas->Files->Lab->Lab9). Develop a simple linear regression model based on least squares that directly predicts Price from Size. Comment on the fit of the model based on the summary of fit and diagnostic plots. Also develop a simple linear regression model that predicts Price from Size (feel free to transform either the predictor or the response variable or both variables) and compare. Can you improve on the original model?

# library(car) #need to install package "car"
# dia <- read.table("diamonds.txt", header=TRUE)
# attach(dia)