Skip to content

Instantly share code, notes, and snippets.

@Zahedasghar
Zahedasghar / Density Plot Pakistan
Created December 17, 2024 02:57
Population Density Plot
pacman::p_load(
arcgis,
geodata,
sf, dots,
tidyverse,
elevatr, terra,
rayshader
)
@Zahedasghar
Zahedasghar / Parameterised
Created November 27, 2024 13:37
Two files: Parameterised reporting , one file is qmd and other is .r
---
title: "Life Expectancy Report"
format: html
execute:
echo: false
warning: false
message: false
params:
country: "Pakistan"
editor_options:
library(tidyverse)
library(readxl)
wide_df <- read_excel("wide_data.xlsx")
wide_df |> View()
wide_df <- wide_df |> mutate(Dec=as.numeric(Dec)) |> na.omit()
wide_df
@Zahedasghar
Zahedasghar / ADF_PP_URT
Created April 20, 2024 06:12
ADF-PP Test
library(zoo) # for time series~ data
library(xts) # for time series data
library(tidyverse) # Umbrella package for data manipulation
library(readxl) # for read_excel function
library(forecast) # for ggAcf and ggPacf functions
library(urca) # for ADF test
library(tseries) # for ADF test
@Zahedasghar
Zahedasghar / ARIMA_enders
Created April 13, 2024 06:09
ARIMA using R
set.seed(33)
library(fpp2)
library(fpp3)
y<-tsibble(sample=1:100,wn=rnorm(100),index=sample)
y %>% autoplot(wn)+ggtitle("White Noise")
y %>% ACF(wn) %>% autoplot()
T<-100
theta <- 0.8
nsim <- 10
@Zahedasghar
Zahedasghar / forecasting.r
Created April 9, 2024 08:15
stationary_nonstationary
library(tidyverse)
library(forecast) # for time series models and auto.arima
library(stats)
library(ggplot2)
phi <- 0.8 # Autoregressive coefficient
n <- 200 # Number of time points
# Simulate data from the AR(1) model
set.seed(123) # For reproducibility
ar1_data <- arima.sim(model = list(ar = phi), n = n)
@Zahedasghar
Zahedasghar / FB_Prophet_R
Created April 4, 2024 10:31
Prophet in R
# Load libraries
#install.packages("prophet") # for forecasting if not already installed
library(prophet) # for forecasting
library(dplyr) # for data manipulation~
# Load data
~
## Simple Exponential Smoothing
## Holt's method
## Holt-Winters method~
## ARIMA method
## ETS method (Error, Trend, Seasonality)
# Load libraries
@Zahedasghar
Zahedasghar / Cointegration_01_data
Created January 3, 2024 12:15
cointegration_data
y z w
-1.80156 -0.49695003 -1.79957
-2.27002 -0.1490799 -2.36988
-2.21743 0.11816769 -2.12782
-2.36609 0.22603459 -2.30212
-2.06364 0.18290678 -1.93444
-2.17761 0.17545464 -1.62233
-1.62946 -0.26589438 -1.67908
-1.93948 0.20289823 -1.66649
-1.88108 0.40078534 -1.71245
@Zahedasghar
Zahedasghar / Cointegration_01
Created January 3, 2024 12:07
Cointegration
## Load relevant libraries
```{r}
#|warning: false
#|message: false
library(readxl) # to read excel data
library(tidyverse)