#GGally -  create a plot matrix for the data visualization.

library(GGally)
## Warning: package 'GGally' was built under R version 4.1.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.1.3
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
data(women)
head(women)
##   height weight
## 1     58    115
## 2     59    117
## 3     60    120
## 4     61    123
## 5     62    126
## 6     63    129
ggpairs(data=women, columns=1:2, title="Death rate")

fit_ex <- lm(height ~ weight, data = women)
ggplot(data=women, aes(fit_ex$residuals)) +
  geom_histogram(binwidth = 1, color = "green", fill = "yellow") +
  theme(panel.background = element_rect(fill = "red"),
        axis.line.x=element_line(),
        axis.line.y=element_line()) +
  ggtitle("Histogram for women height")

ggplot(data = women, aes(x = height, y = weight)) +
  geom_point() +
  stat_smooth(method = "lm", col = "blue") +
  theme(panel.background = element_rect(fill = "grey"),
        axis.line.x=element_line(),
        axis.line.y=element_line()) +
  ggtitle("Linear Model fitted to above data")
## `geom_smooth()` using formula 'y ~ x'

predict(fit_ex, data.frame(weight = 70.2))
##        1 
## 45.88835
summary(fit_ex)
## 
## Call:
## lm(formula = height ~ weight, data = women)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.83233 -0.26249  0.08314  0.34353  0.49790 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 25.723456   1.043746   24.64 2.68e-12 ***
## weight       0.287249   0.007588   37.85 1.09e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.44 on 13 degrees of freedom
## Multiple R-squared:  0.991,  Adjusted R-squared:  0.9903 
## F-statistic:  1433 on 1 and 13 DF,  p-value: 1.091e-14
#Example -2 
x <- c(680, 8713, 18166, 64287, 71600,
       98521, 65324, 152114, 115843,
       531267, 896851, 208725, 3072113)
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.1.3
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(forecast)
## Warning: package 'forecast' was built under R version 4.1.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
cts <- ts(x, start = decimal_date(ymd("2021-02-21")),frequency = 365.25 / 6)
fit <- auto.arima(cts)
forecast(fit, 4)
##          Point Forecast     Lo 80   Hi 80     Lo 95   Hi 95
## 2021.353        3072113 1962765.8 4181460 1375512.9 4768713
## 2021.370        3072113 1503259.2 4640967  672758.1 5471468
## 2021.386        3072113 1150667.3 4993559  133515.4 6010711
## 2021.403        3072113  853418.6 5290807 -321087.2 6465313
plot(forecast(fit, 5), xlab ="Weekly purchase of medicine",ylab ="Total income",main ="purchase vs Income", col.main ="blue")