# \donttest{
# Model: 3D function
distribution = list()
for (i in 1:3) distribution[[i]]=list("norm",c(0,1))
N = 5000
X = matrix(0,ncol=3,nrow=N)
for(i in 1:3) X[,i] = rnorm(N,0,1)
Y = 2 * X[,1] + X[,2] + X[,3]/2
alpha <- 0.95
nboot <- 20 # put nboot=200 for consistency
q95 = quantile(Y,alpha)
v_delta = seq(-1,1,1/10)
toto12 = PLIquantile_multivar(alpha,X,Y,c(1,2),deltasvector=v_delta,
InputDistributions=distribution,samedelta=TRUE)
toto = PLIquantile(alpha,X,Y,deltasvector=v_delta,InputDistributions=distribution,
type="MOY",samedelta=TRUE,nboot=0)
par(mar=c(4,5,1,1))
plot(v_delta,diag(toto12$PLI),,ylim=c(-1,1),xlab=expression(delta),
ylab=expression(hat(PLI[i*delta])),pch=16,cex=1.5,col="blue")
points(v_delta,toto$PLI[,1],col="darkgreen",pch=15,cex=1.5)
points(v_delta,toto$PLI[,2],col="black",pch=19,cex=1.5)
points(v_delta,toto$PLI[,3],col="red",pch=17,cex=1.5)
abline(h=0,lty=2)
legend(-1,1.,legend=c("X1","X2","X3","X1X2"),col=c("darkgreen","black","red","blue"),
pch=c(15,19,17,16),cex=1.5)
# with bootstrap
v_delta = seq(-1,1,2/10)
toto12 = PLIquantile_multivar(alpha,X,Y,c(1,2),deltasvector=v_delta,
InputDistributions=distribution,samedelta=TRUE,nboot=nboot,bootsample=FALSE)
toto = PLIquantile(alpha,X,Y,deltasvector=v_delta,InputDistributions=distribution,
type="MOY",samedelta=TRUE,nboot=nboot,bootsample=FALSE)
par(mar=c(4,5,1,1))
plot(v_delta,diag(toto12$PLI),ylim=c(-1,1),xlab=expression(delta),
ylab=expression(hat(PLI[i*delta])),pch=16,cex=1.5,col="blue")
points(v_delta,toto$PLI[,1],col="darkgreen",pch=15,cex=1.5)
points(v_delta,toto$PLI[,2],col="black",pch=19,cex=1.5)
points(v_delta,toto$PLI[,3],col="red",pch=17,cex=1.5)
lines(v_delta,diag(toto12$PLICIinf),col="blue")
lines(v_delta,diag(toto12$PLICIsup),col="blue")
lines(v_delta,toto$PLICIinf[,2],col="black")
lines(v_delta,toto$PLICIsup[,2],col="black")
lines(v_delta,toto$PLICIinf[,1],col="darkgreen")
lines(v_delta,toto$PLICIsup[,1],col="darkgreen")
lines(v_delta,toto$PLICIinf[,3],col="red")
lines(v_delta,toto$PLICIsup[,3],col="red")
abline(h=0,lty=2)
legend(-1,1,legend=c("X1","X2","X3","X1X2"),col=c("darkgreen","black","red","blue"),
pch=c(15,19,17,16),cex=1.5)
###################################################
# another visualizations by using the plotrix,
# viridisLite, lattice and grid packages (from Vanessa Verges)
library(plotrix)
parameters = list(colors=c("darkgreen","black","red"),symbols=c(15,19,17))
par(mar=c(4,5,1,1),xpd=TRUE)
plotCI(v_delta,diag(toto12$PLI),ui=diag(toto12$PLICIsup),li=diag(toto12$PLICIinf),
xlab=expression(delta),ylab=expression(hat(PLI[i*delta])),
main=bquote("PLI-quantile (N ="~.(N) ~ ","~alpha~"="~.(alpha)~
") on "~X[1]~"and"~X[2]~"of Y="~2*X[1] + X[2] + X[3]/2),
cex=1.5,col="blue",pch=16)
for (i in 1:3){
plotCI(v_delta,toto$PLI[,i],ui=toto$PLICIsup[,i],li=toto$PLICIinf[,i],
cex=1.5,col=parameters$colors[i],pch=parameters$symbols[i],
add=TRUE)
}
abline(h=0,lty=2)
legend("topleft",legend=c("X1","X2","X3","X1X2"),
col=c(parameters$colors,"blue"),pch=c(parameters$symbols,16),cex=1.5)
# Visu of all the PLIs (at any paired combinations of deltas)
library(viridisLite)
library(lattice)
library(grid)
colnames(toto12$PLI) = round(v_delta,2)
rownames(toto12$PLI) = round(v_delta,2)
coul = viridis(100)
levelplot(toto12$PLI, col.regions = coul, xlab=bquote(delta[X~.(1)]), ylab=bquote(delta[X~.(2)]),
main=bquote(hat(PLI)[quantile[~X[1]~X[2]]]))
# }
Run the code above in your browser using DataLab