Skip to content
Back to formatted view

Raw Message

Message-ID: <CAFZ3rQbqm0EtbSMbpEUTdaGfXA90mmjhC+j1NguuRo=x0sgpnA@mail.gmail.com>
Date: 2021-05-23T16:27:17Z
From: Neapyanith Chea
Subject: AR(1) model simulation based on 2 variables

Hello there,
I am currently perform a simulation on an AR(1) model with variable changes
to sample size and population parameter (denoted as ?).
For example, assume that we are simulating an AR(1) model with sample
size ? {10,100} and ??{0.1,0.9} and repeat it 100 times.

This can be done with the help of a looping function (crudely made) below.

  library(readr)
  library(MASS)
  library(dynlm)
  set.seed(2000)
  reps=100
  nv <- c(10,100)
  phi.hat<- matrix(nrow=reps, ncol=length(nv))
  #Looping 100 repeated samples @phi=0.9
  for (i in 1:length(nv)){
    n=nv[i]
    for (j in 1:reps){
    Yi=V=ts(rnorm(n, mean=0, sd=1),start=1, end=n, frequency=1)
    Y=0+0.9*Yi[-1]+V
    eq1=dynlm(Y~L(Y,1))
    phi.hat[j,i]=eq1$coefficients[2]
    }
  }
#Looping 100 repeated samples @ phi=0.1
for (i in 1:length(nv)){
  n=nv[i]
  for (j in 1:reps){
    Yi=V=ts(rnorm(n, mean=0, sd=1),start=1, end=n, frequency=1)
    Y=0+0.1*Yi[-1]+V
    eq1=dynlm(Y~L(Y,1))
    phi.hat[j,i]=eq1$coefficients[2]
  }
}

Having done this, I have received a relatively similar sample coefficient
to population parameter (i.e., mean( phi_hat)  ? phi). However, for
phi=0.9, the value for mean(phi_hat) is not close to phi. I was wondering
why this is the case. Thank you for reading this!

Regards,
Yanith

	[[alternative HTML version deleted]]