wc.at <- read.csv("D:\\New Volume\\DataScience Yogesh\\R _Codes\\Simple Linear Regression\\wc-at.csv") # choose the wc-at.csv data set
dim(wc.at) # dimesnsion of Dataset  
## [1] 109   2
#View(wc.at)
attach(wc.at)
summary(wc.at) # Summary Statistics
##      Waist             AT        
##  Min.   : 63.5   Min.   : 11.44  
##  1st Qu.: 80.0   1st Qu.: 50.88  
##  Median : 90.8   Median : 96.54  
##  Mean   : 91.9   Mean   :101.89  
##  3rd Qu.:104.0   3rd Qu.:137.00  
##  Max.   :121.0   Max.   :253.00
windows()
plot(AT,Waist)

#plot(x,y) # Syntax
# Correlation coefficient value for Waist and FAT Data
#cor(x,y) # Syntax
cor(AT,Waist)
## [1] 0.8185578
cor(Waist,AT)
## [1] 0.8185578
#dim(wc.at)
class(wc.at)
## [1] "data.frame"
colnames(wc.at)
## [1] "Waist" "AT"
str(wc.at)
## 'data.frame':    109 obs. of  2 variables:
##  $ Waist: num  74.8 72.6 81.8 84 74.7 ...
##  $ AT   : num  25.7 25.9 42.6 42.8 29.8 ...
sum
## function (..., na.rm = FALSE)  .Primitive("sum")
sd(Waist)
## [1] 13.55912
# Implementation of Linear

m1 <- lm(AT ~ Waist,data = wc.at)
summary(m1)
## 
## Call:
## lm(formula = AT ~ Waist, data = wc.at)
## 
## 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 ***
## 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
PV <- predict(m1,newdata = wc.at)
PV
##          1          2          3          4          5          6          7 
##  42.568252  35.131704  66.953210  74.389758  42.222366  32.537559  63.840237 
##          8          9         10         11         12         13         14 
##  72.487385   3.656083  37.207020  32.710502  43.432966  36.861134  57.268404 
##         15         16         17         18         19         20         21 
##  50.350685  22.160981  46.718883  40.492936  39.282335  46.545940  49.831856 
##         22         23         24         25         26         27         28 
##  63.840237  60.381377  92.548770  67.644982 102.233576  83.555735  62.456693 
##         29         30         31         32         33         34         35 
##  81.480420  69.374412  72.833271  88.744024  98.082945  93.240542 136.822170 
##         36         37         38         39         40         41         42 
## 110.880725  98.774717 140.281029  60.727263  57.268404  72.833271  46.891826 
##         43         44         45         46         47         48         49 
##  62.456693  83.209849  71.103842 154.462353 110.188953 110.880725  59.689606 
##         50         51         52         53         54         55         56 
##  58.306062  94.624085  73.870929  78.713332  45.162396  55.193088  55.884860 
##         57         58         59         60         61         62         63 
##  87.706367  82.518078  79.750990  73.525043  52.426001  77.675674  60.035492 
##         64         65         66         67         68         69         70 
## 158.612984 197.698095 198.735753 117.798443 148.928178 147.198748 154.116467 
##         71         72         73         74         75         76         77 
## 154.116467 133.363311 119.527873 129.904451 157.575326 129.904451 140.281029 
##         78         79         80         81         82         83         84 
## 143.739889 150.657608 161.034186 142.010459 164.493045 164.493045 171.410764 
##         85         86         87         88         89         90         91 
## 159.304756 143.739889 167.951905 159.304756 202.540498 161.034186 121.257303 
##         92         93         94         95         96         97         98 
## 148.928178 122.986732 110.880725 119.527873 147.198748 150.657608 126.445592 
##         99        100        101        102        103        104        105 
##  98.774717 138.551600 150.657608 161.380072 181.787342 133.363311 130.250337 
##        106        107        108        109 
## 106.730093 136.130398 157.229440 159.304756
class(PV)
## [1] "numeric"
PV <- as.data.frame(PV)

final1 <-cbind(wc.at,PV)

x <- read.csv("D:\\New Volume\\DataScience Yogesh\\R _Codes\\Simple Linear Regression\\x.csv") # choose the wc-at.csv data set


pred1 <- predict(m1,newdata = x)
pred1
##         1         2         3         4 
##  40.31999 -19.86416  36.86113   9.88203
m2 <- lm(log(AT) ~ Waist,data = wc.at)
summary(m2)
## 
## Call:
## lm(formula = log(AT) ~ Waist, data = wc.at)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.05086 -0.21688  0.03623  0.23044  0.82862 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.741021   0.232628   3.185  0.00189 ** 
## Waist       0.040252   0.002504  16.073  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3529 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