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:

library(gdata)
## Warning: package 'gdata' was built under R version 3.2.3
## gdata: Unable to locate valid perl interpreter
## gdata: 
## gdata: read.xls() will be unable to read Excel XLS and XLSX files
## gdata: unless the 'perl=' argument is used to specify the location
## gdata: of a valid perl intrpreter.
## gdata: 
## gdata: (To avoid display of this message in the future, please
## gdata: ensure perl is installed and available on the executable
## gdata: search path.)
## gdata: Unable to load perl libaries needed by read.xls()
## gdata: to support 'XLX' (Excel 97-2004) files.
## 
## gdata: Unable to load perl libaries needed by read.xls()
## gdata: to support 'XLSX' (Excel 2007+) files.
## 
## gdata: Run the function 'installXLSXsupport()'
## gdata: to automatically download and install the perl
## gdata: libaries needed to support Excel XLS and XLSX formats.
## 
## Attaching package: 'gdata'
## The following object is masked from 'package:stats':
## 
##     nobs
## The following object is masked from 'package:utils':
## 
##     object.size
require(gdata)

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

wcdata <- read.csv('wc-at.csv', header = TRUE, sep=",")

plot(wcdata$Waist,wcdata$AT,xlab='Waist Circumference', ylab='Adipose Tissue', main='Scatterplot: Waist Circumference Vs Adipose Tissue')

linreg <- lm(wcdata$AT~wcdata$Waist)
abline(linreg, col='red')

linreg$residuals
##            1            2            3            4            5 
##  -16.8482516   -9.2417039  -24.3532103  -31.5897580  -12.3823657 
##            6            7            8            9           10 
##  -10.8575594  -34.7602369  -39.5073853    7.7839166   -4.9870195 
##           11           12           13           14           15 
##   -4.3905023    0.4270336    1.3488664  -14.7884040  -19.3906852 
##           16           17           18           19           20 
##   33.6190188   -2.9388829   -7.0829360    4.0676648  -17.2359399 
##           21           22           23           24           25 
##  -13.2318563  -23.5902369  -24.9513775  -32.4587698  -21.8049822 
##           26           27           28           29           30 
##  -31.8335761   -0.1057354   21.8433069   -2.5904198   -4.6244119 
##           31           32           33           34           35 
##   -0.2732713    0.5659755  -19.1429448   -9.6905417   -9.8221700 
##           36           37           38           39           40 
##   10.1192754    8.2252833  -11.2810294   13.2927366   -1.7884040 
##           41           42           43           44           45 
##    0.2967287    3.6081742  -11.5766931   56.7901506   25.4361584 
##           46           47           48           49           50 
##  -36.4623529   -3.1889527   12.1192754    6.2303944   22.9839382 
##           51           52           53           54           55 
##   16.3759146   16.8590709   54.2866678   -3.2623961  -13.4830884 
##           56           57           58           59           60 
##    2.2751397    1.1436333   72.4819224   -8.9809901    1.5549568 
##           61           62           63           64           65 
##    4.6239991   22.0543256  -32.0754915  -35.6129842 -107.2880953 
##           66           67           68           69           70 
##  -92.7357531   26.2015566  -27.9281779  -50.0687482   11.8835330 
##           71           72           73           74           75 
##  -66.1264670   20.6366894  -19.5278731   -6.9044512   59.4246736 
##           76           77           78           79           80 
##   10.0955488  -31.2810294  -16.7398888  -38.6576076   30.9658142 
##           81           82           83           84           85 
##  -10.0104591  -38.4930452  -11.4930452  -13.4107639   23.6952439 
##           86           87           88           89           90 
##   40.2601112  -46.9519046   -0.3047561   42.4595015  -24.0341858 
##           91           92           93           94           95 
##   43.7426972    3.0718221   58.0132675  -29.9307246   17.4721269 
##           96           97           98           99          100 
##  -22.1987482   90.3423924    7.5544082   51.2252833   59.4484003 
##          101          102          103          104          105 
##    0.3423924   67.6199283   71.2126579   54.6366894   -6.2503372 
##          106          107          108          109 
##  -44.5300933   -3.1303981   50.7705596   48.6952439
mean(linreg$residuals)
## [1] 1.40624e-16
summary((linreg))
## 
## Call:
## lm(formula = wcdata$AT ~ wcdata$Waist)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -107.288  -19.143   -2.939   16.376   90.342 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -215.9815    21.7963  -9.909   <2e-16 ***
## wcdata$Waist    3.4589     0.2347  14.740   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 33.06 on 107 degrees of freedom
## Multiple R-squared:   0.67,  Adjusted R-squared:  0.667 
## F-statistic: 217.3 on 1 and 107 DF,  p-value: < 2.2e-16
#Log

plot(wcdata$Waist, log10(wcdata$AT),xlab='Waist Circumference', ylab='Adipose Tissue', main='Scatterplot: Waist Circumference Vs Adipose Tissue')

linreg <- lm(log10(wcdata$AT)~wcdata$Waist)
abline(linreg, col='red')

linreg$residuals
##            1            2            3            4            5 
## -0.218285117 -0.177839014 -0.122390376 -0.157941224 -0.152009122 
##            6            7            8            9           10 
## -0.241800734 -0.272472310 -0.261519570 -0.373464268 -0.093334370 
##           11           12           13           14           15 
## -0.126640833  0.009142195 -0.017534728 -0.074667538 -0.177088287 
##           16           17           18           19           20 
##  0.221062709 -0.008258008 -0.094190764  0.025040354 -0.181643877 
##           21           22           23           24           25 
## -0.101785943 -0.131300828 -0.169214157 -0.102360157 -0.094051647 
##           26           27           28           29           30 
## -0.082537631  0.085715629  0.196753424  0.071800086  0.047202815 
##           31           32           33           34           35 
##  0.079178913  0.088967272 -0.011835484  0.037287813 -0.001120604 
##           36           37           38           39           40 
##  0.108971571  0.116754891 -0.011816018  0.149015631  0.041284407 
##           41           42           43           44           45 
##  0.082577212  0.052883543 -0.022527048  0.312165464  0.211929635 
##           46           47           48           49           50 
## -0.122197475  0.059066259  0.116091313  0.103928170  0.201940657 
##           51           52           53           54           55 
##  0.153671776  0.170988129  0.312614894 -0.019453111 -0.072123014 
##           56           57           58           59           60 
##  0.068764913  0.091969036  0.359865407  0.033368028  0.090509622 
##           61           62           63           64           65 
##  0.077877568  0.192833493 -0.270300002 -0.125152055 -0.456380556 
##           66           67           68           69           70 
## -0.392535581  0.149585886 -0.083323866 -0.170015146  0.027776746 
##           71           72           73           74           75 
## -0.247898024  0.100077800 -0.017517307  0.019943594  0.126646989 
##           76           77           78           79           80 
##  0.076166518 -0.084979230 -0.036083410 -0.125631916  0.056007080 
##           81           82           83           84           85 
## -0.010572498 -0.144405007 -0.060084121 -0.081081272  0.043897643 
##           86           87           88           89           90 
##  0.124930692 -0.179471585 -0.017156322 -0.047904905 -0.090573581 
##           91           92           93           94           95 
##  0.191225935  0.015734351  0.222679864 -0.065596946  0.119203260 
##           96           97           98           99          100 
## -0.060458522  0.207167104  0.074624684  0.263462372  0.183000164 
##          101          102          103          104          105 
##  0.004127009  0.130793193  0.070937952  0.186714928  0.021712027 
##          106          107          108          109 
## -0.159045730  0.022423597  0.109998730  0.099509888
mean(linreg$residuals)
## [1] 7.291757e-18
summary((linreg))
## 
## Call:
## lm(formula = log10(wcdata$AT) ~ wcdata$Waist)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.45638 -0.09419  0.01573  0.10008  0.35987 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.321821   0.101029   3.185  0.00189 ** 
## wcdata$Waist 0.017481   0.001088  16.073  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1533 on 107 degrees of freedom
## Multiple R-squared:  0.7071, Adjusted R-squared:  0.7044 
## F-statistic: 258.3 on 1 and 107 DF,  p-value: < 2.2e-16
#Sqrt

#Log

plot(wcdata$Waist, sqrt(wcdata$AT), xlab='Waist Circumference', ylab='Adipose Tissue', main='Scatterplot: Waist Circumference Vs Adipose Tissue')

linreg <- lm(sqrt(wcdata$AT)~wcdata$Waist)
abline(linreg, col='red')

linreg$residuals
##            1            2            3            4            5 
## -1.507975642 -1.103585286 -1.323753328 -1.696107579 -1.098833876 
##            6            7            8            9           10 
## -1.400398895 -2.295758099 -2.396288644 -1.168716763 -0.623724116 
##           11           12           13           14           15 
## -0.743939000 -0.001852764 -0.100536124 -0.828096179 -1.420981659 
##           16           17           18           19           20 
##  1.952940930 -0.179185929 -0.691142653  0.175897679 -1.372945239 
##           21           22           23           24           25 
## -0.908313493 -1.344056834 -1.555729270 -1.433110239 -1.116157697 
##           26           27           28           29           30 
## -1.299269847  0.419008156  1.565279884  0.274098796  0.069903492 
##           31           32           33           34           35 
##  0.361074939  0.463849032 -0.588555090 -0.080376491 -0.223371547 
##           36           37           38           39           40 
##  0.859494721  0.834645658 -0.315288384  1.077417333  0.102725307 
##           41           42           43           44           45 
##  0.394467200  0.301488304 -0.483201461  3.134101155  1.758489181 
##           46           47           48           49           50 
## -1.549578604  0.239636326  0.950031228  0.647134678  1.616240486 
##           51           52           53           54           55 
##  1.242586009  1.313997062  3.068901799 -0.241673036 -0.779253001 
##           56           57           58           59           60 
##  0.352628256  0.493571768  3.787902358 -0.105261840  0.471669601 
##           61           62           63           64           65 
##  0.459808769  1.576921837 -2.202287533 -1.538189619 -5.157765002 
##           66           67           68           69           70 
## -4.424643942  1.498883004 -1.123869722 -2.178261450  0.489770218 
##           71           72           73           74           75 
## -3.014030006  1.097180287 -0.591269925 -0.041650994  2.156285495 
##           76           77           78           79           80 
##  0.699972066 -1.232798567 -0.583983264 -1.631017406  1.101466235 
##           81           82           83           84           85 
## -0.274132712 -1.710273924 -0.565929208 -0.726052711  0.862961962 
##           86           87           88           89           90 
##  1.711249032 -2.115551943 -0.055267084  0.733865315 -1.050240315 
##           91           92           93           94           95 
##  2.163809725  0.204958284  2.682048264 -1.143283485  1.113429986 
##           96           97           98           99          100 
## -0.853376905  3.310152046  0.623955261  2.738013940  2.488295133 
##          101          102          103          104          105 
##  0.074183077  2.359775139  2.069198344  2.398815842 -0.014689360 
##          106          107          108          109 
## -2.037440587  0.075824549  1.865601320  1.757417805
mean(linreg$residuals)
## [1] -9.771745e-18
summary((linreg))
## 
## Call:
## lm(formula = sqrt(wcdata$AT) ~ wcdata$Waist)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.1578 -1.1162 -0.0147  0.9500  3.7879 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -6.89840    1.03576   -6.66 1.22e-09 ***
## wcdata$Waist  0.18031    0.01115   16.17  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.571 on 107 degrees of freedom
## Multiple R-squared:  0.7096, Adjusted R-squared:  0.7069 
## F-statistic: 261.5 on 1 and 107 DF,  p-value: < 2.2e-16
newspdata <- read.csv('NewspaperData.csv', header= TRUE, sep=",")

Including Plots

You can also embed plots, for example:

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