This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
meddcor = read.table("meddcor-4.txt", sep="", header = FALSE)
n = dim(meddcor)[1] # number of observations
colnames(meddcor) = c("sales", "advertising", "bonuses", "marketshare", "largestcomp", "region")
meddcor$region = as.factor(meddcor$region)
model = lm(sales ~ advertising, data = meddcor)
summary(model)
##
## Call:
## lm(formula = sales ~ advertising, data = meddcor)
##
## Residuals:
## Min 1Q Median 3Q Max
## -137.56 -92.63 -19.54 97.51 170.12
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -157.3301 145.1912 -1.084 0.29
## advertising 2.7721 0.2794 9.921 8.87e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 101.4 on 23 degrees of freedom
## Multiple R-squared: 0.8106, Adjusted R-squared: 0.8024
## F-statistic: 98.43 on 1 and 23 DF, p-value: 8.873e-10
plot(model$fitted, model$residuals, xlab = "Response Variable", ylab="Residuals", pty=2, lwd=2)
plot(meddcor$advertising, meddcor$sales, xlab="Advertising Expenditure",ylab="Sales",pty=2,lwd=2)
library(car); qqPlot(model$residuals,ylab="Residuals")
## Warning: package 'car' was built under R version 4.3.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.3.3
## [1] 19 5
hist(model$residuals, xlab="Residuals",main="")
summary(model)$r.squared
## [1] 0.8105919
summary(model)$adjr.squared
## NULL
1- pt(9.921, 23)
## [1] 4.438411e-10
confint(model, level=0.99)
## 0.5 % 99.5 %
## (Intercept) -564.930546 250.27032
## advertising 1.987712 3.55652
summary(model)$r.squared
## [1] 0.8105919
summary(model)$adj.r.squared
## [1] 0.8023567