mydata<-read.csv("E:\\Yogesh BGLR Data Science Videos\\Aug'19\\50_Startups.CSV")
View(mydata)
attach(mydata)
mydata <- mydata[, c("Marketing.Spend", "Profit")]
mydata
##    Marketing.Spend    Profit
## 1        471784.10 192261.83
## 2        443898.53 191792.06
## 3        407934.54 191050.39
## 4        383199.62 182901.99
## 5        366168.42 166187.94
## 6        362861.36 156991.12
## 7        127716.82 156122.51
## 8        323876.68 155752.60
## 9        311613.29 152211.77
## 10       304981.62 149759.96
## 11       229160.95 146121.95
## 12       249744.55 144259.40
## 13       249839.44 141585.52
## 14       252664.93 134307.35
## 15       256512.92 132602.65
## 16       261776.23 129917.04
## 17       264346.06 126992.93
## 18       282574.31 125370.37
## 19       294919.57 124266.90
## 20            0.00 122776.86
## 21       298664.47 118474.03
## 22       299737.29 111313.02
## 23       303319.26 110352.25
## 24       304768.73 108733.99
## 25       140574.81 108552.04
## 26       137962.62 107404.34
## 27       134050.07 105733.54
## 28       353183.81 105008.31
## 29       118148.20 103282.38
## 30       107138.38 101004.64
## 31        91131.24  99937.59
## 32        88218.23  97483.56
## 33        46085.25  97427.84
## 34       214634.81  96778.92
## 35       210797.67  96712.80
## 36       205517.64  96479.51
## 37       201126.82  90708.19
## 38       197029.42  89949.14
## 39       185265.10  81229.06
## 40       174999.30  81005.76
## 41       172795.67  78239.91
## 42       164470.71  77798.83
## 43       148001.11  71498.49
## 44        35534.17  69758.98
## 45        28334.72  65200.33
## 46         1903.93  64926.08
## 47       297114.46  49490.75
## 48            0.00  42559.73
## 49            0.00  35673.41
## 50        45173.06  14681.40
mean(Profit)
## [1] 112012.6
dim(mydata)
## [1] 50  2
summary(mydata)
##  Marketing.Spend      Profit      
##  Min.   :     0   Min.   : 14681  
##  1st Qu.:129300   1st Qu.: 90139  
##  Median :212716   Median :107978  
##  Mean   :211025   Mean   :112013  
##  3rd Qu.:299469   3rd Qu.:139766  
##  Max.   :471784   Max.   :192262
qqnorm(Profit)

windows()
plot(Profit ~ Marketing.Spend)

cor(mydata)
##                 Marketing.Spend    Profit
## Marketing.Spend       1.0000000 0.7477657
## Profit                0.7477657 1.0000000
m1 <- lm(Profit ~ Marketing.Spend)
summary(m1)
## 
## Call:
## lm(formula = Profit ~ Marketing.Spend)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -83739 -18802   4925  15879  64642 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     6.000e+04  7.685e+03   7.808 4.29e-10 ***
## Marketing.Spend 2.465e-01  3.159e-02   7.803 4.38e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 27040 on 48 degrees of freedom
## Multiple R-squared:  0.5592, Adjusted R-squared:   0.55 
## F-statistic: 60.88 on 1 and 48 DF,  p-value: 4.381e-10
pv <- predict(m1,mydata)
class(pv)
## [1] "numeric"
Pv <- as.data.frame(pv)
pv
##         1         2         3         4         5         6         7 
## 176279.11 169406.45 160542.80 154446.65 150249.15 149434.09  91480.54 
##         8         9        10        11        12        13        14 
## 139825.96 136803.53 135169.09 116482.39 121555.41 121578.79 122275.16 
##        15        16        17        18        19        20        21 
## 123223.53 124520.73 125154.08 129646.61 132689.21  60003.55 133612.17 
##        22        23        24        25        26        27        28 
## 133876.58 134759.39 135116.63  94649.51  94005.71  93041.43 147048.97 
##        29        30        31        32        33        34        35 
##  89122.27  86408.80  82463.69  81745.75  71361.69 112902.29 111956.59 
##        36        37        38        39        40        41        42 
## 110655.28 109573.12 108563.27 105663.85 103133.75 102590.64 100538.88 
##        43        44        45        46        47        48        49 
##  96479.79  68761.27  66986.90  60472.79 133230.16  60003.55  60003.55 
##        50 
##  71136.87
Finalreport <- cbind(mydata,pv)
Finalreport
##    Marketing.Spend    Profit        pv
## 1        471784.10 192261.83 176279.11
## 2        443898.53 191792.06 169406.45
## 3        407934.54 191050.39 160542.80
## 4        383199.62 182901.99 154446.65
## 5        366168.42 166187.94 150249.15
## 6        362861.36 156991.12 149434.09
## 7        127716.82 156122.51  91480.54
## 8        323876.68 155752.60 139825.96
## 9        311613.29 152211.77 136803.53
## 10       304981.62 149759.96 135169.09
## 11       229160.95 146121.95 116482.39
## 12       249744.55 144259.40 121555.41
## 13       249839.44 141585.52 121578.79
## 14       252664.93 134307.35 122275.16
## 15       256512.92 132602.65 123223.53
## 16       261776.23 129917.04 124520.73
## 17       264346.06 126992.93 125154.08
## 18       282574.31 125370.37 129646.61
## 19       294919.57 124266.90 132689.21
## 20            0.00 122776.86  60003.55
## 21       298664.47 118474.03 133612.17
## 22       299737.29 111313.02 133876.58
## 23       303319.26 110352.25 134759.39
## 24       304768.73 108733.99 135116.63
## 25       140574.81 108552.04  94649.51
## 26       137962.62 107404.34  94005.71
## 27       134050.07 105733.54  93041.43
## 28       353183.81 105008.31 147048.97
## 29       118148.20 103282.38  89122.27
## 30       107138.38 101004.64  86408.80
## 31        91131.24  99937.59  82463.69
## 32        88218.23  97483.56  81745.75
## 33        46085.25  97427.84  71361.69
## 34       214634.81  96778.92 112902.29
## 35       210797.67  96712.80 111956.59
## 36       205517.64  96479.51 110655.28
## 37       201126.82  90708.19 109573.12
## 38       197029.42  89949.14 108563.27
## 39       185265.10  81229.06 105663.85
## 40       174999.30  81005.76 103133.75
## 41       172795.67  78239.91 102590.64
## 42       164470.71  77798.83 100538.88
## 43       148001.11  71498.49  96479.79
## 44        35534.17  69758.98  68761.27
## 45        28334.72  65200.33  66986.90
## 46         1903.93  64926.08  60472.79
## 47       297114.46  49490.75 133230.16
## 48            0.00  42559.73  60003.55
## 49            0.00  35673.41  60003.55
## 50        45173.06  14681.40  71136.87
View(Finalreport)
write.csv(Finalreport, "Simple Linear Regression.CSV")