Skip to content

Commit

Permalink
Misc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ppernot committed May 10, 2023
1 parent 51fc9d7 commit 9c14e08
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
4 changes: 3 additions & 1 deletion R/plotLZISD.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ plotLZISD = function(
}

# Mean + CI
pm = signif(mV0,2)
pm = round(mV0,2)
mtext(text = paste0('- ',pm),
side = 4,
at = mV0,
Expand Down Expand Up @@ -341,6 +341,8 @@ plotLZISD = function(
pcl = loV,
pcu = upV,
meanP = mV0,
meanPl = loV0,
meanPu = upV0,
ZISDE = ZISDE,
ZISDEUp= ZISDEUp,
ZISDM = ZISDM,
Expand Down
47 changes: 37 additions & 10 deletions R/plotLZV.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ varZCI = function (
#' @param plot (logical) plot the results
#' @param xlab (string) X axis label
#' @param xlim (vector) min and max values of X axis
#' @param score (logical) estimate calibration stats (default: `FALSE`)
#' @param add (logical) add to previous graph ?
#' @param col (integer) color index of curve to add
#'
Expand Down Expand Up @@ -146,6 +147,7 @@ plotLZV = function(
xlim = NULL,
ylim = NULL,
title = '',
score = FALSE,
add = FALSE,
col = 5,
label = 0,
Expand Down Expand Up @@ -203,7 +205,7 @@ plotLZV = function(
nBoot = max(nBoot, N),
method = method,
CImethod = BSmethod)
mV0 = zs$mean
mV0 = zs$mean
loV0 = zs$ci[1]
upV0 = zs$ci[2]

Expand Down Expand Up @@ -304,14 +306,17 @@ plotLZV = function(

# Mean variance
ypos = par("usr")[4]
pm = signif(mV0,2)
mtext(text = c(' Average',paste0('- ',pm)),
side = 4,
at = c(ypos,mV0),
col = c(1,cols[col]),
cex = 0.75*cex,
las = 1,
font = 2)
pm = round(mV0, digits = 2)
mtext(
text = c(
' Average',
paste0('- ', pm)),
side = 4,
at = c(ypos, mV0),
col = c(1,cols[col]),
cex = 0.75*cex,
las = 1,
font = 2)
segments(
xlim[2],loV0,
xlim[2],upV0,
Expand All @@ -330,6 +335,22 @@ plotLZV = function(

}

ZVE = ZVEUp = ZVDM = ZVMs = NA
if(score) {
scores = abs(log(mV))
# Max deviation
im = which.max(scores)
ZVM = exp( sign(log(mV[im])) * scores[im] )
# Significant ?
ZVMs = FALSE
if(varZ < loV[im] | varZ > upV[im])
ZVMs = TRUE
# Mean deviation
ZVE = exp(mean(scores))
scores = pmax(log(upV/mV),log(mV/loV))
ZVEUp = exp(mean(scores))
}

invisible(
list(
mint = mint,
Expand All @@ -338,7 +359,13 @@ plotLZV = function(
pc = mV,
pcl = loV,
pcu = upV,
meanP = mV0
meanP = mV0,
meanPl = loV0,
meanPu = upV0,
ZVE = ZVE,
ZVEUp = ZVEUp,
ZVM = ZVM,
ZVMs = ZVMs
)
)
}
44 changes: 35 additions & 9 deletions R/plotRelDiag.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ sdZCI = function (
#'
#' @param X (vector) vector of uncertainties
#' @param Y (vector) vector of errors
#' @param aux (vector) auxilliary vector to resolve ties in X sorting
#' @param ordX (vector) set of abscissas to order sample
#' @param aux (vector) auxilliary vector to resolve ties in sample sorting
#' @param intrv (object) intervals generated by `genIntervals` (default: `NULL`)
#' @param nBin (integer) number of intervals for local coverage stats
#' @param slide (logical) use sliding window for subsetting (X,Z)
Expand Down Expand Up @@ -104,6 +105,7 @@ sdZCI = function (
#' }
plotRelDiag = function(
X, Y,
ordX = NULL,
aux = NULL,
logX = FALSE,
nBin = NULL,
Expand Down Expand Up @@ -132,10 +134,21 @@ plotRelDiag = function(

N = length(Y)

if(is.null(aux))
ord = order(X)
else
ord = order(X,aux)
if(!is.null(ordX)) {
if(length(ordX) != N)
stop('>>> Inconsistent length for ordX')
# Order by ordX, aux
if(is.null(aux))
ord = order(ordX)
else
ord = order(ordX,aux)
} else {
# Order by X, aux
if(is.null(aux))
ord = order(X)
else
ord = order(X,aux)
}
xOrd = X[ord]
yOrd = Y[ord]

Expand All @@ -146,8 +159,12 @@ plotRelDiag = function(
if(nBin <= 0)
stop('>>> nBin should be > 0')
Xin = N
if(!equiPop)
Xin = xOrd
if(!equiPop) {
if(!is.null(ordX))
Xin = ordX[ord]
else
Xin = xOrd
}
intrv = ErrViewLib::genIntervals(Xin, nBin, slide, equiPop, popMin, logBin)
}
nBin0 = nBin
Expand All @@ -169,10 +186,18 @@ plotRelDiag = function(
upV[i] = zs$ci[2]
mint[i] = sqrt(mean(xOrd[sel] ^ 2))
}
io = order(mint)
mint = mint[io]
mV = mV[io]
loV = loV[io]
upV = upV[io]

ENCE = NA
if(score)
MNCE = NA
if(score) {
ENCE = mean(abs(mV-mint)/mint)
MNCE = max(abs(mV-mint)/mint)
}


if(plot) {
Expand Down Expand Up @@ -285,7 +310,8 @@ plotRelDiag = function(
pc = mV,
pcl = loV,
pcu = upV,
ENCE = ENCE
ENCE = ENCE,
MNCE = MNCE
)
)
}
3 changes: 3 additions & 0 deletions man/plotLZV.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/plotRelDiag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c14e08

Please sign in to comment.