Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/draw_from_depth.R
This function transforms a given empirical simplicial depth to a distribution function and generates random numbers from this distribution by inversion as proposed in Kustosz (2016).
1 | draw_from_depth(depthI, testvec, lower, upper)
|
depthI |
Values of an empirical depth calculation. |
testvec |
Parameters of the empirical depth vector defined by depthI. |
lower |
A lower candidate value to restrict the depth on an interval [lower,upper]. |
upper |
A upper candidate value to restrict the depth on an interval [lower,upper]. |
For details see Kustosz (2016).
The function returns a simulated parameter theta.
Christoph Kustosz and Sebastian Szugat
Kustosz, C. (2016). Depth based estimators and tests for
autoregressive processes with application. Ph. D. thesis. TU Dortmund.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | set.seed(234)
y <- RandomARMod_lin2(100, 0, 1.01, 15, "0")
#evaluate depth on grid
thetas <- seq(0.97, 1.05, 0.001)
dS <- unlist(lapply(thetas, dS_lin1, y=y))
#plot emprirical depth
par(mfrow=c(2, 2))
plot(thetas, dS)
#generate random parameters
tmi <- min(thetas[dS>0])
tma <- max(thetas[dS>0])
rand_theta <- replicate(10000, draw_from_depth(dS, thetas, lower=tmi, upper=tma))
#plot 'discrete' distribution on grid and empirical distribution
plot(table(rand_theta)/length(rand_theta), type="h")
plot(ecdf(rand_theta))
#plot process and generate trajectories with estimated variance
#we now assume normally distributed errors with mean 0 for simulations
plot(y, type="l")
yy <- matrix(ncol=100, nrow=100)
for(i in 1:100)
{
rt <- sample(rand_theta, 1)
res <- resARMod_lin2(c(0, rt), y)
sd_est <- sd(res)
yy[i, ] <- RandomARMod_lin2(100, 0, rt, y[1], sd=sd_est)
if(floor(i/10)==i/10)
{
lines(yy[i, ],col=i)
}
mean_f <- apply(yy, 2, mean)
lines(mean_f, col=2, lwd=2)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.