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(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'ggplot2' was built under R version 4.3.2
## Warning: package 'tibble' was built under R version 4.3.2
## Warning: package 'tidyr' was built under R version 4.3.2
## Warning: package 'readr' was built under R version 4.3.2
## Warning: package 'purrr' was built under R version 4.3.2
## Warning: package 'dplyr' was built under R version 4.3.2
## Warning: package 'stringr' was built under R version 4.3.2
## Warning: package 'forcats' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.3.2
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.3.2
library(xts)
## Warning: package 'xts' was built under R version 4.3.2
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.2
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'xts'
##
## The following objects are masked from 'package:dplyr':
##
## first, last
library(tsibble)
## Warning: package 'tsibble' was built under R version 4.3.2
##
## Attaching package: 'tsibble'
##
## The following object is masked from 'package:zoo':
##
## index
##
## The following object is masked from 'package:lubridate':
##
## interval
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, union
datas <- read.csv("C:\\Users\\karth\\Downloads\\Child Growth and Malnutrition.csv")
view(datas)
typeof(datas$Year.period)
## [1] "character"
datas1 <- datas
datas1$Median.Year <- as.Date(datas1$Median.Year, format = "%Y")
view(datas1)
Time column - Median Year Response Variable - Stunting
datas1$Median.Year[is.na(datas1$Median.Year)]<-mean(datas1$Median.Year,na.rm=TRUE)
datas1$Stunting[is.na(datas1$Stunting)]<-mean(datas1$Stunting,na.rm=TRUE)
datas2 <- datas1 |>
group_by(Median.Year) |>
summarise(height = mean(Stunting))
view(datas2)
height_ts <- as_tsibble(datas2, index = Median.Year, key = height)
height_ts
## # A tsibble: 58 x 2 [1.58324837684631e-08D]
## # Key: height [57]
## Median.Year height
## <date> <dbl>
## 1 1969-11-12 3.7
## 2 1971-11-12 7.09
## 3 1984-11-12 10.8
## 4 1981-11-12 12.3
## 5 2021-11-12 20.7
## 6 2019-11-12 21.0
## 7 2017-11-12 21.7
## 8 1990-11-12 22.3
## 9 2012-11-12 22.3
## 10 2014-11-12 23.0
## # ℹ 48 more rows
height_ts |>
drop_na() |>
filter_index("2001" ~ "2022") |>
ggplot() +
geom_point(mapping = aes(x = Median.Year, y = height)) +
labs(title = "Height Deficit in the 21st Century") +
theme_hc()
height_ts |>
drop_na() |>
filter_index("1971" ~ "2000") |>
ggplot() +
geom_point(mapping = aes(x = Median.Year, y = height)) +
labs(title = "Height Deficit from 1971 to 2000") +
theme_hc()
From the above 2 graphs, we see that the height deficit has gone down by the years, from the start when the data has been recorded. A clear indication of the improving health in the countries
lr <- lm(height ~ Median.Year, data = height_ts)
summary(lr)
##
## Call:
## lm(formula = height ~ Median.Year, data = height_ts)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.119 -6.031 -3.405 2.953 40.696
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.182e+01 1.784e+00 17.83 <2e-16 ***
## Median.Year 2.244e-06 1.877e-05 0.12 0.905
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.58 on 56 degrees of freedom
## Multiple R-squared: 0.0002552, Adjusted R-squared: -0.0176
## F-statistic: 0.0143 on 1 and 56 DF, p-value: 0.9053
The coefficient and the intercept tell us that there is a downward trend for the average deficit in height over the years
pacf(height_ts$height, ci = 0.95, na.action = na.exclude, xlab = "height lag", main = "PACF")