simulAr1Ar1 | R Documentation |
Simulate random samples from a separable AR1xAR1 process as in Martin (1996).
simulAr1Ar1(
n = 1,
R = 2,
C = 2,
rho.r = 0,
rho.c = 0,
sigma.X.2 = 1,
sigma.e.2 = 1
)
n |
number of samples |
R |
number of rows |
C |
number of columns |
rho.r |
correlation between rows |
rho.c |
correlation between columns |
sigma.X.2 |
variance of X (see Martin, 1996, page 400) |
sigma.e.2 |
variance of epsilons (see Martin, 1996, page 400) |
array which first dimension is R, second is C and third is n
Timothee Flutre
## Not run: ## strong correlation only between rows
set.seed(1234)
samples <- simulAr1Ar1(n=100, R=40, C=45, rho.r=0.8, rho.c=0)
dim(samples)
stats <- list()
stats$cor.btw.rows <- c(apply(samples, 3, function(mat){
apply(mat, 2, function(row.i){ # per column
acf(row.i, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
stats$cor.btw.cols <- c(apply(samples, 3, function(mat){
apply(mat, 1, function(col.j){ # per row
acf(col.j, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
sapply(stats, summary)
## strong correlation only between columns
set.seed(1234)
samples <- simulAr1Ar1(n=100, R=40, C=45, rho.r=0, rho.c=0.8)
stats <- list()
stats$cor.btw.rows <- c(apply(samples, 3, function(mat){
apply(mat, 2, function(row.i){ # per column
acf(row.i, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
stats$cor.btw.cols <- c(apply(samples, 3, function(mat){
apply(mat, 1, function(col.j){ # per row
acf(col.j, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
sapply(stats, summary)
## strong correlation between rows and between columns
set.seed(1234)
samples <- simulAr1Ar1(n=100, R=40, C=45, rho.r=0.8, rho.c=0.8)
stats <- list()
stats$cor.btw.rows <- c(apply(samples, 3, function(mat){
apply(mat, 2, function(row.i){ # per column
acf(row.i, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
stats$cor.btw.cols <- c(apply(samples, 3, function(mat){
apply(mat, 1, function(col.j){ # per row
acf(col.j, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
sapply(stats, summary)
## low correlation between rows and strong correlation between columns
set.seed(1234)
samples <- simulAr1Ar1(n=100, R=40, C=45, rho.r=0.2, rho.c=0.8)
stats <- list()
stats$cor.btw.rows <- c(apply(samples, 3, function(mat){
apply(mat, 2, function(row.i){ # per column
acf(row.i, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
stats$cor.btw.cols <- c(apply(samples, 3, function(mat){
apply(mat, 1, function(col.j){ # per row
acf(col.j, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
sapply(stats, summary)
## low correlation between rows and strong correlation between columns
## AND high error variance
set.seed(1234)
samples <- simulAr1Ar1(n=100, R=40, C=45, rho.r=0.2, rho.c=0.8,
sigma.X.2=1, sigma.e.2=200)
stats <- list()
stats$cor.btw.rows <- c(apply(samples, 3, function(mat){
apply(mat, 2, function(row.i){ # per column
acf(row.i, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
stats$cor.btw.cols <- c(apply(samples, 3, function(mat){
apply(mat, 1, function(col.j){ # per row
acf(col.j, lag.max=1, type="correlation", plot=FALSE)$acf[2]
})}))
sapply(stats, summary)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.