R Markdown

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:

setwd('C:/Users/praisons/Documents/CBA/Term3/SA2')

newspdata <- read.csv('NewspaperData.csv', header=TRUE, sep = ',')

head(newspdata)
##            Newspaper   daily   sunday
## 1      Baltimore Sun 391.952  488.506
## 2       Boston Globe 516.981  798.298
## 3      Boston Herald 355.628  235.084
## 4 Charlotte Observer 238.555  299.451
## 5  Chicago Sun Times 537.780  559.093
## 6    Chicago Tribune 733.775 1133.249
plot(x = newspdata$daily,y=newspdata$sunday)

reg <- lm(newspdata$sunday~newspdata$daily)
abline(reg, col='green')

summary(reg)
## 
## Call:
## lm(formula = newspdata$sunday ~ newspdata$daily)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -255.19  -55.57  -20.89   62.73  278.17 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     13.83563   35.80401   0.386    0.702    
## newspdata$daily  1.33971    0.07075  18.935   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 109.4 on 32 degrees of freedom
## Multiple R-squared:  0.9181, Adjusted R-squared:  0.9155 
## F-statistic: 358.5 on 1 and 32 DF,  p-value: < 2.2e-16
plot(x = newspdata$daily,y=reg$residuals)
reg <- lm(reg$residuals~newspdata$daily)
abline(reg, col='green')

summary(reg)
## 
## Call:
## lm(formula = reg$residuals ~ newspdata$daily)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -255.19  -55.57  -20.89   62.73  278.17 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)
## (Intercept)      7.920e-15  3.580e+01       0        1
## newspdata$daily -1.838e-17  7.075e-02       0        1
## 
## Residual standard error: 109.4 on 32 degrees of freedom
## Multiple R-squared:  3.467e-33,  Adjusted R-squared:  -0.03125 
## F-statistic: 1.109e-31 on 1 and 32 DF,  p-value: 1
#Log
plot(x = log10(newspdata$daily),y=newspdata$sunday)

reg <- lm(newspdata$sunday~log10(newspdata$daily))
abline(reg, col='green')

summary(reg)
## 
## Call:
## lm(formula = newspdata$sunday ~ log10(newspdata$daily))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -334.71  -99.04   -9.73   66.58  440.31 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             -3039.0      309.5  -9.818 3.55e-11 ***
## log10(newspdata$daily)   1414.7      120.1  11.778 3.58e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 165.5 on 32 degrees of freedom
## Multiple R-squared:  0.8126, Adjusted R-squared:  0.8067 
## F-statistic: 138.7 on 1 and 32 DF,  p-value: 3.582e-13
plot(x = log10(newspdata$daily),y=reg$residuals)
reg <- lm(reg$residuals~log10(newspdata$daily))
abline(reg, col='green')

summary(reg)
## 
## Call:
## lm(formula = reg$residuals ~ log10(newspdata$daily))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -334.71  -99.04   -9.73   66.58  440.31 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)
## (Intercept)            -3.831e-14  3.095e+02       0        1
## log10(newspdata$daily)  2.063e-14  1.201e+02       0        1
## 
## Residual standard error: 165.5 on 32 degrees of freedom
## Multiple R-squared:  5.493e-33,  Adjusted R-squared:  -0.03125 
## F-statistic: 1.758e-31 on 1 and 32 DF,  p-value: 1
#Square root
plot(x = sqrt(newspdata$daily),y=newspdata$sunday)

reg <- lm(newspdata$sunday~sqrt(newspdata$daily))
abline(reg, col='green')

summary(reg)
## 
## Call:
## lm(formula = newspdata$sunday ~ sqrt(newspdata$daily))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -290.778  -84.726   -0.811   71.632  274.859 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           -613.144     79.912  -7.673 9.57e-09 ***
## sqrt(newspdata$daily)   60.399      3.849  15.690  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 129.6 on 32 degrees of freedom
## Multiple R-squared:  0.885,  Adjusted R-squared:  0.8814 
## F-statistic: 246.2 on 1 and 32 DF,  p-value: < 2.2e-16
plot(x = sqrt(newspdata$daily),y=reg$residuals)
reg <- lm(reg$residuals~sqrt(newspdata$daily))
abline(reg, col='green')

summary(reg)
## 
## Call:
## lm(formula = reg$residuals ~ sqrt(newspdata$daily))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -290.778  -84.726   -0.811   71.632  274.859 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)
## (Intercept)            1.085e-14  7.991e+01       0        1
## sqrt(newspdata$daily) -4.219e-16  3.849e+00       0        1
## 
## Residual standard error: 129.6 on 32 degrees of freedom
## Multiple R-squared:  1.357e-32,  Adjusted R-squared:  -0.03125 
## F-statistic: 4.341e-31 on 1 and 32 DF,  p-value: 1

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.