Title: | Tools to Support the Sheffield Elicitation Framework |
---|---|
Description: | Implements various methods for eliciting a probability distribution for a single parameter from an expert or a group of experts. The expert provides a small number of probability judgements, corresponding to points on his or her cumulative distribution function. A range of parametric distributions can then be fitted and displayed, with feedback provided in the form of fitted probabilities and percentiles. For multiple experts, a weighted linear pool can be calculated. Also includes functions for eliciting beliefs about population distributions; eliciting multivariate distributions using a Gaussian copula; eliciting a Dirichlet distribution; eliciting distributions for variance parameters in a random effects meta-analysis model; survival extrapolation. R Shiny apps for most of the methods are included. |
Authors: | Jeremy Oakley [aut, cre] |
Maintainer: | Jeremy Oakley <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 1.11.0.9000 |
Built: | 2024-11-08 05:31:18 UTC |
Source: | https://github.com/oakleyj/shelf |
Report the median and 100(1-alpha)% credible interval for point on the population CDF
cdffeedback( medianfit, precisionfit, quantiles = c(0.05, 0.95), vals = NA, alpha = 0.05, median.dist = "best", precision.dist = "gamma", n.rep = 10000 )
cdffeedback( medianfit, precisionfit, quantiles = c(0.05, 0.95), vals = NA, alpha = 0.05, median.dist = "best", precision.dist = "gamma", n.rep = 10000 )
medianfit |
The output of a fitdist command following elicitation of the expert's beliefs about the population median. |
precisionfit |
The output of a fitprecision command following elicitation of the expert's beliefs about the population precision. |
quantiles |
A vector of quantiles |
vals |
A vector of population values |
alpha |
The size of the 100(1-alpha)% credible interval |
median.dist |
The fitted distribution for the population median. Can be one of |
precision.dist |
The fitted distribution for the population precision. Can either be |
n.rep |
The number of randomly sampled CDFs used to estimated the median and credible interval. |
Denote the uncertain population CDF by
where
is the uncertain population median and
is the uncertain population precision.
Feedback can be reported in the form of the median and 100(1-alpha)% credible interval for
(a) an uncertain probability
, where
is a specified
population value and (b) an uncertain quantile
defined by
, where
is a specified
population probability.
Fitted median and 100(1-alpha)% credible interval for population quantiles and probabilities.
$quantiles |
Each row gives the fitted median
and 100(1-alpha)% credible interval for each uncertain population quantile
specified in |
$probs |
Each row gives the fitted median
and 100(1-alpha)% credible interval for each uncertain population probability
specified in |
## Not run: prfit <- fitprecision(interval = c(60, 70), propvals = c(0.2, 0.4), trans = "log") medianfit <- fitdist(vals = c(50, 60, 70), probs = c(0.05, 0.5, 0.95), lower = 0) cdffeedback(medianfit, prfit, quantiles = c(0.01, 0.99), vals = c(65, 75), alpha = 0.05, n.rep = 10000) ## End(Not run)
## Not run: prfit <- fitprecision(interval = c(60, 70), propvals = c(0.2, 0.4), trans = "log") medianfit <- fitdist(vals = c(50, 60, 70), probs = c(0.05, 0.5, 0.95), lower = 0) cdffeedback(medianfit, prfit, quantiles = c(0.01, 0.99), vals = c(65, 75), alpha = 0.05, n.rep = 10000) ## End(Not run)
Plot the elicited pointwise median and credible interval for an uncertain population CDF
cdfplot( medianfit, precisionfit, lower = NA, upper = NA, ql = 0.025, qu = 0.975, median.dist = "best", precision.dist = "gamma", n.rep = 10000, n.X = 100, fontsize = 18 )
cdfplot( medianfit, precisionfit, lower = NA, upper = NA, ql = 0.025, qu = 0.975, median.dist = "best", precision.dist = "gamma", n.rep = 10000, n.X = 100, fontsize = 18 )
medianfit |
The output of a |
precisionfit |
The output of a |
lower |
lower limit on the x-axis for plotting. |
upper |
upper limit on the x-axis for plotting. |
ql |
lower quantile for the plotted pointwise credible interval. |
qu |
upper quantile for the plotted pointwise credible interval. |
median.dist |
The fitted distribution for the population median. Can be one of |
precision.dist |
The fitted distribution for the population precision. Can either be |
n.rep |
The number of randomly sampled CDFs used to estimated the median and credible interval. |
n.X |
The number of points on the x-axis at which the CDF is evaluated. |
fontsize |
Font size used in the plots. |
## Not run: prfit <- fitprecision(interval = c(60, 70), propvals = c(0.2, 0.4), trans = "log") medianfit <- fitdist(vals = c(50, 60, 70), probs = c(0.05, 0.5, 0.95), lower = 0) cdfplot(medianfit, prfit) ## End(Not run)
## Not run: prfit <- fitprecision(interval = c(60, 70), propvals = c(0.2, 0.4), trans = "log") medianfit <- fitdist(vals = c(50, 60, 70), probs = c(0.05, 0.5, 0.95), lower = 0) cdfplot(medianfit, prfit) ## End(Not run)
Produce one of three plots to compare the individual elicited judgements with the final elicited distribution, chosen to represent the views of a "Rational Impartatial Observer" (RIO) as part of the SHELF process. A linear pool of fitted distributions from the individually elicited judgements is also obtained. The plot choices are a display of the quartiles, a display of the tertiles, and a plot of the various density functions.
compareGroupRIO( groupFit, RIOFit, type = "density", dLP = "best", dRIO = "best", xlab = "x", ylab = expression(f[X](x)), fs = 12 )
compareGroupRIO( groupFit, RIOFit, type = "density", dLP = "best", dRIO = "best", xlab = "x", ylab = expression(f[X](x)), fs = 12 )
groupFit |
either an object of class |
RIOFit |
an object of class |
type |
the plot used to show the comparison: one of "quartiles", "tertiles" or "density". |
dLP |
the distribution fitted to each expert's judgements and to the linear pool. Options are Options are "normal", "t", "gamma", "lognormal", "logt","beta", "mirrorgamma", "mirrorlognormal", "mirrorlogt" "hist" (for a histogram fit), and "best" (for best fitting). |
dRIO |
the distribution fitted to RIO's judgements. Options are the same as for |
xlab |
x-axis label in plot |
ylab |
y-axis label in plot |
fs |
font size used in plot |
Jeremy Oakley <[email protected]>
## Not run: l <- c(2, 1, 5, 1) u <- c(95, 90, 65, 40) v <- matrix(c(15, 25, 40, 10, 20, 40, 10, 15, 25, 5, 10, 20), 3, 4) p <- c(0.25, 0.5, 0.75) group <- fitdist(vals = v, probs = p, lower = l, upper = u) rio <- fitdist(vals = c(12, 20, 25), probs = p, lower = 1, upper = 100) compareGroupRIO(groupFit = group, RIOFit = rio, dRIO = "gamma") ## End(Not run)
## Not run: l <- c(2, 1, 5, 1) u <- c(95, 90, 65, 40) v <- matrix(c(15, 25, 40, 10, 20, 40, 10, 15, 25, 5, 10, 20), 3, 4) p <- c(0.25, 0.5, 0.75) group <- fitdist(vals = v, probs = p, lower = l, upper = u) rio <- fitdist(vals = c(12, 20, 25), probs = p, lower = 1, upper = 100) compareGroupRIO(groupFit = group, RIOFit = rio, dRIO = "gamma") ## End(Not run)
Following elicitation of distributions from individual experts, plot fitted probability intervals for each expert.
compareIntervals( fit, interval = 0.95, dist = "best", fs = 12, xlab = "x", ylab = "expert", showDist = TRUE )
compareIntervals( fit, interval = 0.95, dist = "best", fs = 12, xlab = "x", ylab = "expert", showDist = TRUE )
fit |
An object of class |
interval |
The probability p for each interval (i.e. the fitted probability for each expert that the displayed interval contains the uncertain quantity will be p) |
dist |
The distribution fitted to each expert's probabilities. Options are
|
fs |
font size used in the plot. |
xlab |
A string or expression giving the x-axis label. |
ylab |
A string or expression giving the y-axis label. |
showDist |
TRUE/FALSE for reporting distributions used for each expert |
## Not run: v <- matrix(c(30, 40, 50, 20, 25, 35, 40, 50, 60, 35, 40, 50), 3, 4) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) compareIntervals(myfit, interval = 0.5) ## End(Not run)
## Not run: v <- matrix(c(30, 40, 50, 20, 25, 35, 40, 50, 60, 35, 40, 50), 3, 4) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) compareIntervals(myfit, interval = 0.5) ## End(Not run)
Takes elicited marginal distributions and elicited concordance probabilities: pairwise probabilities of two uncertain quantities being greater than their medians, and generates a correlated sample, assuming the elicited marginal distributions and a multivariate normal copula. A vignette explaining this method is available at https://oakleyj.github.io/SHELF/Multivariate-normal-copula.html
copulaSample(..., cp, n, d = NULL, ex = 1)
copulaSample(..., cp, n, d = NULL, ex = 1)
... |
A list of objects of class |
cp |
A matrix of pairwise concordance probabilities, with element i,j the elicited probability P(X_i > m_i, X_j > m_j or X_i < m_i, X_j < m_j), where m_i and m_j are the elicited medians of the uncertain quantities X_i and X_j. Only the upper triangular elements in the matrix need to be specified; the remaining elements can be set at 0. |
n |
The sample size to be generated |
d |
A vector of distributions to be used for each elicited quantity: a string with elements chosen from
|
ex |
If separate judgements have been elicited from multiple experts and stored
in the |
A matrix of sampled values, one row per sample.
Jeremy Oakley [email protected]
## Not run: p1 <- c(0.25, 0.5, 0.75) v1 <- c(0.5, 0.55, 0.6) v2 <- c(0.22, 0.3, 0.35) v3 <- c(0.11, 0.15, 0.2) myfit1 <- fitdist(v1, p1, 0, 1) myfit2 <- fitdist(v2, p1, 0, 1) myfit3 <- fitdist(v3, p1, 0, 1) quad.probs <- matrix(0, 3, 3) quad.probs[1, 2] <- 0.4 quad.probs[1, 3] <- 0.4 quad.probs[2, 3] <- 0.3 copulaSample(myfit1, myfit2, myfit3, cp=quad.probs, n=100, d=NULL) ## End(Not run)
## Not run: p1 <- c(0.25, 0.5, 0.75) v1 <- c(0.5, 0.55, 0.6) v2 <- c(0.22, 0.3, 0.35) v3 <- c(0.11, 0.15, 0.2) myfit1 <- fitdist(v1, p1, 0, 1) myfit2 <- fitdist(v2, p1, 0, 1) myfit3 <- fitdist(v3, p1, 0, 1) quad.probs <- matrix(0, 3, 3) quad.probs[1, 2] <- 0.4 quad.probs[1, 3] <- 0.4 quad.probs[2, 3] <- 0.3 copulaSample(myfit1, myfit2, myfit3, cp=quad.probs, n=100, d=NULL) ## End(Not run)
Opens up a web browser (using the shiny package), from which you can specify judgements, fit distributions and plot the fitted density functions with additional feedback. Probabilities can be specified directly, or the roulette elicitation method can be used.
elicit(lower = 0, upper = 100, gridheight = 10, nbins = 10, method = "general")
elicit(lower = 0, upper = 100, gridheight = 10, nbins = 10, method = "general")
lower |
A lower limit for the uncertain quantity X. Will be ignored when fitting distributions that are not bounded below. Also sets the lower limit for the grid in the roulette method. |
upper |
An upper limit for the uncertain quantity X. Will be ignored when fitting distributions that are not bounded above. Also sets the upper limit for the grid in the roulette method. |
gridheight |
The number of grid cells for each bin in the roulette method. |
nbins |
The number of bins used in the rouletted method. |
method |
Set to "roulette" for the app to display the roulette method by default. Any other string will display the general method by default. |
All input arguments are optional, and can be set/changed within the app itself.
Click on the "Help" tab for instructions. Click the "Quit" button to exit the app and return
the results from the fitdist
command. Click "Download report" to generate a report
of all the fitted distributions.
An object of class elicitation
, which is returned once the
Quit button has been clicked. See fitdist
for details.
Jeremy Oakley <[email protected]>
## Not run: elicit() ## End(Not run)
## Not run: elicit() ## End(Not run)
Opens up a web browser (using the shiny package), from which you can specify judgements, fit distributions, plot the fitted density functions, and plot samples from the joint distributions. A joint distribution is constructed using a Gaussian copula, whereby the correlation parameter is determined via the elicitation of a concordance probability (a probability that the two uncertain quantities are either both greater than their medians, or both less than their medians.)
elicitBivariate()
elicitBivariate()
Click on the "Help" tab for instructions. Click the "Quit" button to exit the app and return
the results from the fitdist
command. Click "Download report" to generate a report
of all the fitted distributions for each uncertain quantity, and "Download sample" to
generate a csv file with a sample from the joint distribution.
A list, with two objects of class elicitation
, and the
elicited concordance probability. See fitdist
for details.
Jeremy Oakley <[email protected]>
## Not run: elicitBivariate() ## End(Not run)
## Not run: elicitBivariate() ## End(Not run)
Opens up a web browser (using the shiny package), from which you can elicit a Dirichlet distribution
elicitDirichlet()
elicitDirichlet()
Click on the "Help" tab for instructions. Click the "Quit" button to exit the app and return
the results from the fitdist
command. Click "Download report" to generate a report
of all the fitted distributions.
The parameters of the fitted Dirichlet distribution, which are returned once the Quit button has been clicked.
Jeremy Oakley <[email protected]>
## Not run: elicitDirichlet() ## End(Not run)
## Not run: elicitDirichlet() ## End(Not run)
Opens up a web browser (using the shiny package), from which you can specify judgements, fit distributions, and produce various plots. Judgements are specified for the distribution of the conditioning variable Y, the median function (median of X given Y), and the distribution of X given that Y takes its median value. Plots are provided for the two elicited distributions, the median function, the conditional distribution of X for any specified Y, and the marginal distribution of X.
elicitExtension()
elicitExtension()
Click the "Quit" button to exit the app and return
the results from the fitdist
command. Click "Download report" to generate a report
of all the fitted distributions for each uncertain quantity, and "Download sample" to
generate a csv file with a sample from the marginal distribution of X.
A list, with two objects of class elicitation
.
See fitdist
for details.
Jeremy Oakley <[email protected]>
## Not run: elicitExtension() ## End(Not run)
## Not run: elicitExtension() ## End(Not run)
Opens a shiny app for the roulette elicitation method. The user clicks in the grid to allocate 'probs' to 'bins'. The elicited probability inside each bin is the proportion of probs in each bin. This will fit a distribution to the ratio R of the 'largest' (97.5th percentile) to 'smallest' (2.5th percentile) treatment effect. A distribution for the variance effects variance parameter is inferred from the distribution of R, assuming that the random effects are normally distributed.
elicitHeterogen( lower = 1, upper = 10, gridheight = 10, nbins = 9, scale.free = TRUE, sigma = 1 )
elicitHeterogen( lower = 1, upper = 10, gridheight = 10, nbins = 9, scale.free = TRUE, sigma = 1 )
lower |
The lower limit on the x-axis of the roulette grid. |
upper |
The upper limit on the x-axis of the roulette grid. |
gridheight |
The maximum number of probs that can be allocated to a single bin. |
nbins |
The number of equally sized bins drawn between |
scale.free |
Logical. Default is |
sigma |
Individual observation standard deviation, required if |
BUGS code for incorporating the prior within a BUGS model. Additionally, a list with outputs
allocation |
table of bins, with number of probs allocated to each bin. |
Gamma |
parameters of the fitted gamma distribution. |
Log.normal |
parameters of the fitted lognormal distribution. |
sumsq |
sum of squares of elicited - fitted probabilities for each distribution. |
best.fitting |
the distribution with the lowest sum of squares. |
Regarding the option “spread end probs over empty bins” (unchecked as the default): suppose for example, the leftmost and rightmost non-empty bins are [10,20] and [70,80], and each contain one prob, with 20 probs used in total. If the option is unchecked, it is assumed P(X<20) = P(X>70) = 0.05 and P(X<10) = P(X>80) = 0. If the option is checked, it is assumed P(X<20) = P(X>70) = 0.05 only.
Jeremy Oakley <[email protected]>
## Not run: elicitHeterogen() ## End(Not run)
## Not run: elicitHeterogen() ## End(Not run)
Opens up a web browser (using the shiny package), from which you can specify judgements, fit distributions and plot the fitted density function.
elicitMixture()
elicitMixture()
Click the "Quit" button to exit the app and return the fitted distributions. Click "Download report" to generate a report of all the fitted distributions.
When the Quit button is clicked, a list, with elements
fit |
an object of class |
extensionProbs |
the probability mass function for the extension variable. |
Jeremy Oakley <[email protected]>
## Not run: elicitMixture() ## End(Not run)
## Not run: elicitMixture() ## End(Not run)
Opens up a web browser (using the shiny package), from which you can specify judgements, fit distributions and plot the fitted density functions and a (weighted) linear pool with additional feedback.
elicitMultiple()
elicitMultiple()
Click the "Quit" button to exit the app and return
the results from the fitdist
command. Click "Download report" to generate a report
of all the fitted distributions.
An object of class elicitation
, which is returned once the
Finish button has been clicked. See fitdist
for details.
Jeremy Oakley <[email protected]>
## Not run: elicitMultiple() ## End(Not run)
## Not run: elicitMultiple() ## End(Not run)
Opens up a web browser in which you can implement the SHELF protocol for survival extrapolation. Start with uploading a .csv file of individual patient survival data (time, event to indicate censoring, and treatment group). Then elicit individual judgements, perform scenario testing as required, and elicit a RIO distribution. Judgements for two treatment groups can be elicited in the same session.
elicitSurvivalExtrapolation()
elicitSurvivalExtrapolation()
Jeremy Oakley <[email protected]>
## Not run: # make a suitable csv file using a built in data set from the survival package sdf <- survival::veteran[, c("time", "status", "trt")] colnames(sdf) <- c("time", "event", "treatment") sdf$treatment <- factor(sdf$treatment, labels = c("standard", "test")) # write the data frame sdf to a .csv file in the current working directory write.csv(sdf, file = "testFile.csv", row.names = FALSE) # Run the app and upload testFile.csv in the first tab, and change unit of time to "days" elicitSurvivalExtrapolation() ## End(Not run)
## Not run: # make a suitable csv file using a built in data set from the survival package sdf <- survival::veteran[, c("time", "status", "trt")] colnames(sdf) <- c("time", "event", "treatment") sdf$treatment <- factor(sdf$treatment, labels = c("standard", "test")) # write the data frame sdf to a .csv file in the current working directory write.csv(sdf, file = "testFile.csv", row.names = FALSE) # Run the app and upload testFile.csv in the first tab, and change unit of time to "days" elicitSurvivalExtrapolation() ## End(Not run)
Having fitted appropriate distributions to one or more expert's judgements
individually using the fitdist
command, use this command to
get quantiles and probabilities from the fitted distributions
feedback(fit, quantiles = NA, values = NA, dist = "best", ex = NA, sf = 3)
feedback(fit, quantiles = NA, values = NA, dist = "best", ex = NA, sf = 3)
fit |
An object of class |
quantiles |
A vector of desired quantiles for feedback. If this argument is left out, the default is to use the same quantiles that were elicited from the experts. |
values |
A vector of desired probabilities; desired values of a for reporting back fitted values of P(X<a). If this argument is left out, the default is to use the same values provided by the experts. |
dist |
If |
ex |
If |
sf |
The number of significant figures to be displayed in the output. |
fitted.quantiles |
Fitted quantiles for each expert |
fitted.probabilities |
Fitted probabilities for each expert |
distributions |
The distribution used to calculate fitted probabilities/quantiles for each expert, if feedback is given for multiple experts. |
Jeremy Oakley <[email protected]>
## Not run: # Two experts # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) feedback(myfit) # Feedback P(X<60) and the tertiles feedback(myfit, values=60, quantiles=c(0.33,0.66)) # Compare fitted tertiles for different distributions, expert 2 only feedback(myfit, quantiles=c(0.33,0.66), ex=2) ## End(Not run)
## Not run: # Two experts # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) feedback(myfit) # Feedback P(X<60) and the tertiles feedback(myfit, values=60, quantiles=c(0.33,0.66)) # Compare fitted tertiles for different distributions, expert 2 only feedback(myfit, quantiles=c(0.33,0.66), ex=2) ## End(Not run)
Given a (elicited) Dirichlet distribution, calculate quantiles for each marginal beta distribution corresponding to the elicited quantiles
feedbackDirichlet(d, quantiles = c(0.1, 0.9), sf = 2)
feedbackDirichlet(d, quantiles = c(0.1, 0.9), sf = 2)
d |
A vector of parameters of the Dirichlet distribution |
quantiles |
The desired quantiles for feedback |
sf |
The number of significant figures displayed |
Quantiles for each marginal distribution
Jeremy Oakley <[email protected]>
## Not run: feedbackDirichlet(d = c(20, 10, 5), quantiles = c(0.1, 0.33, 0.66, 0.9)) ## End(Not run)
## Not run: feedbackDirichlet(d = c(20, 10, 5), quantiles = c(0.1, 0.33, 0.66, 0.9)) ## End(Not run)
Takes elicited beta distributions for a set of proportions as inputs, and fits a Dirichlet distribution. The beta parameters are adjusted so that the expectations sum to 1, and then the sum of the Dirichlet parameters is chosen based on the sums of the beta parameters for each elicited marginal
fitDirichlet( ..., categories = NULL, n.fitted = "opt", plotBeta = TRUE, xlab = "x", ylab = expression(f[X](x)), fs = 12, silent = FALSE )
fitDirichlet( ..., categories = NULL, n.fitted = "opt", plotBeta = TRUE, xlab = "x", ylab = expression(f[X](x)), fs = 12, silent = FALSE )
... |
Multiple arguments, each an objects of class |
categories |
A vector of strings labelling the marginal proportions. |
n.fitted |
The method used to determine the sum of the Dirichlet parameters.
Use |
plotBeta |
logical. Plot the original elicited marginals and the fitted marginals from the Dirichlet fit. |
xlab |
x-axis label on the marginal distribution plot. |
ylab |
y-axis label on the marginal distribution plot. |
fs |
The font size used in the plot. |
silent |
Set to |
The parameters of the fitted Dirichlet distribution.
Jeremy Oakley <[email protected]>
Zapata-Vazquez, R., O'Hagan, A. and Bastos, L. S. (2014). Eliciting expert judgements about a set of proportions. Journal of Applied Statistics 41, 1919-1933.
## Not run: p1 <- c(0.25, 0.5, 0.75) v1 <- c(0.5, 0.55, 0.6) v2 <- c(0.22, 0.3, 0.35) v3 <- c(0.11, 0.15, 0.2) myfit1 <- fitdist(v1, p1, 0, 1) myfit2 <- fitdist(v2, p1, 0, 1) myfit3 <- fitdist(v3, p1, 0, 1) d <- fitDirichlet(myfit1, myfit2, myfit3, categories = c("A","B","C"), n.fitted = "opt") # Note that this will also work: d <- fitDirichlet(list(myfit1, myfit2, myfit3), categories = c("A","B","C"), n.fitted = "opt") ## End(Not run)
## Not run: p1 <- c(0.25, 0.5, 0.75) v1 <- c(0.5, 0.55, 0.6) v2 <- c(0.22, 0.3, 0.35) v3 <- c(0.11, 0.15, 0.2) myfit1 <- fitdist(v1, p1, 0, 1) myfit2 <- fitdist(v2, p1, 0, 1) myfit3 <- fitdist(v3, p1, 0, 1) d <- fitDirichlet(myfit1, myfit2, myfit3, categories = c("A","B","C"), n.fitted = "opt") # Note that this will also work: d <- fitDirichlet(list(myfit1, myfit2, myfit3), categories = c("A","B","C"), n.fitted = "opt") ## End(Not run)
Takes elicited probabilities as inputs, and fits parametric distributions using least squares on the cumulative distribution function. If separate judgements from multiple experts are specified, the function will fit one set of distributions per expert.
fitdist( vals, probs, lower = -Inf, upper = Inf, weights = 1, tdf = 3, expertnames = NULL, excludelogt = FALSE )
fitdist( vals, probs, lower = -Inf, upper = Inf, weights = 1, tdf = 3, expertnames = NULL, excludelogt = FALSE )
vals |
A vector of elicited values for one expert, or a matrix of elicited values for multiple experts (one column per expert). Note that the an elicited judgement about X should be of the form P(X<= vals[i,j]) = probs[i,j] |
probs |
A vector of elicited probabilies for one expert, or a matrix of
elicited values for multiple experts (one column per expert). A single
vector can be used if the probabilities are the same for each expert. For
each expert, there should be at least one non-zero probability less than 0.4, and
at least one elicited probability less and 1 and greater than 0.6. Exponential distributions
can be fitted by specifying one limit ( |
lower |
A single lower limit for the uncertain quantity X, or a vector of different lower limits for each expert. Specifying a lower limit will allow the fitting of distributions bounded below. |
upper |
A single upper limit for the uncertain quantity X, or a vector of different lower limits for each expert. Specifying both a lower limit and an upper limit will allow the fitting of a Beta distribution. |
weights |
A vector or matrix of weights corresponding to vals if weighted least squares is to be used in the parameter fitting. |
tdf |
The number of degrees of freedom to be used when fitting a t-distribution. |
expertnames |
Vector of names to use for each expert. |
excludelogt |
Set to TRUE to exclude log-t and mirror log-t when identifying best fitting distribution. |
An object of class elicitation
. This is a list containing the elements
Normal |
Parameters of the fitted normal distributions. |
Student.t |
Parameters of the fitted t distributions. Note that (X -
location) / scale has a standard t distribution. The degrees of freedom is
not fitted; it is specified as an argument to |
Skewnormal |
Parameters of the fitted skew-normal distribution. The skew-normal distribution is implemented using the sn package. See sn::dsn for details. This distribution requires at least three elicited probabilities, including at least one in each interval (0, 0.4) and (0.6, 1). |
Gamma |
Parameters of the fitted gamma distributions. Note that E(X - |
Log.normal |
Parameters of the fitted log normal
distributions: the mean and standard deviation of log (X - |
Log.Student.t |
Parameters of the fitted log student t distributions.
Note that (log(X- |
Beta |
Parameters of the fitted beta distributions. X
is scaled to the interval [0,1] via Y = (X - |
mirrorgamma |
Parameters of ('mirror') gamma distributions fitted to Y = |
mirrorlognormal |
Parameters of ('mirror') log normal distributions
fitted to Y = |
mirrorlogt |
Parameters of ('mirror') log Student-t distributions fitted to Y = |
ssq |
Sum of squared errors for each fitted distribution and expert. Each error is the difference between an elicited cumulative probability and the corresponding fitted cumulative probability. |
best.fitting |
The best fitting distribution for each expert, determined by the smallest sum of squared errors. Note that with three judgements only, this is likely to be the skew-normal, as this is a three parameter distribution. |
vals |
The elicited values used to fit the distributions. |
probs |
The elicited probabilities used to fit the distributions. |
limits |
The lower and upper limits specified by each expert (+/- Inf if not specified). |
The least squares parameter values are found numerically using the
optim
command. Starting values for the distribution parameters are
chosen based on a simple normal approximation: linear interpolation is used
to estimate the 0.4, 0.5 and 0.6 quantiles, and starting parameter values
are chosen by setting E(X) equal to the 0.5th quantile, and Var(X) = (0.6
quantile - 0.4 quantile)^2 / 0.25. Note that the arguments lower
and
upper
are not included as elicited values on the cumulative
distribution function. To include a judgement such as P(X<=a)=0, the values
a and 0 must be included in vals
and probs
respectively.
Jeremy Oakley <[email protected]>
## Not run: # One expert, with elicited probabilities # P(X<20)=0.25, P(X<30)=0.5, P(X<50)=0.75 # and X>0. v <- c(20,30,50) p <- c(0.25,0.5,0.75) fitdist(vals=v, probs=p, lower=0) # Now add a second expert, with elicited probabilities # P(X<55)=0.25, P(X<60=0.5), P(X<70)=0.75 v <- matrix(c(20,30,50,55,60,70),3,2) p <- c(0.25,0.5,0.75) fitdist(vals=v, probs=p, lower=0) # Two experts, different elicited quantiles and limits. # Expert A: P(X<50)=0.25, P(X<60=0.5), P(X<65)=0.75, and provides bounds 10<X<100 # Expert B: P(X<40)=0.33, P(X<50=0.5), P(X<60)=0.66, and provides bounds 0<X v <- matrix(c(50,60,65,40,50,60),3,2) p <- matrix(c(.25,.5,.75,.33,.5,.66),3,2) l <- c(10,0) u <- c(100, Inf) fitdist(vals=v, probs=p, lower=l, upper=u) ## End(Not run)
## Not run: # One expert, with elicited probabilities # P(X<20)=0.25, P(X<30)=0.5, P(X<50)=0.75 # and X>0. v <- c(20,30,50) p <- c(0.25,0.5,0.75) fitdist(vals=v, probs=p, lower=0) # Now add a second expert, with elicited probabilities # P(X<55)=0.25, P(X<60=0.5), P(X<70)=0.75 v <- matrix(c(20,30,50,55,60,70),3,2) p <- c(0.25,0.5,0.75) fitdist(vals=v, probs=p, lower=0) # Two experts, different elicited quantiles and limits. # Expert A: P(X<50)=0.25, P(X<60=0.5), P(X<65)=0.75, and provides bounds 10<X<100 # Expert B: P(X<40)=0.33, P(X<50=0.5), P(X<60)=0.66, and provides bounds 0<X v <- matrix(c(50,60,65,40,50,60),3,2) p <- matrix(c(.25,.5,.75,.33,.5,.66),3,2) l <- c(10,0) u <- c(100, Inf) fitdist(vals=v, probs=p, lower=l, upper=u) ## End(Not run)
Takes elicited probabilities about proportion of a population lying in a specfied interval as inputs, converts the judgements into probability judgements about the population precision, and fits gamma and lognormal distributions to these judgements using the fitdist function.
fitprecision( interval, propvals, propprobs = c(0.05, 0.95), med = interval[1], trans = "identity", pplot = TRUE, tdf = 3, fontsize = 12 )
fitprecision( interval, propvals, propprobs = c(0.05, 0.95), med = interval[1], trans = "identity", pplot = TRUE, tdf = 3, fontsize = 12 )
interval |
A vector specifying the endpoints of an interval |
propvals |
A vector specifying two values |
propprobs |
A vector specifying two probabilities |
med |
The hypothetical value of the population median. |
trans |
A string variable taking the value |
pplot |
Plot the population distributions with median set at |
tdf |
Degrees of freedom in the fitted log Student-t distribution. |
fontsize |
Font size used in the plots. |
The expert provides a pair of probability judgements
and
where is the proportion of the population that lies in the interval
, conditional on the population median taking some hypothetical value (
by default).
can be set to
-Inf
, or can be set to
Inf
;
in either case, the hypothetical median value must be specified. If both
and
are finite, the hypothetical median must be one of the interval endpoints.
Note that, unlike the fitdist command, a 'best fitting'
distribution is not reported, as the distributions are fitted to two elicited
probabilities only.
Gamma |
Parameters of the fitted gamma distribution. Note that E(precision) = shape / rate. |
Log.normal |
Parameters of the fitted log normal distribution: the mean and standard deviation of log precision. |
Log.Student.t |
Parameters of the fitted log student t distributions.
Note that (log(X- |
vals |
The elicited values |
probs |
The elicited probabilities |
limits |
The lower and upper limits specified by each expert (+/- Inf if not specified). |
transform |
Transformation used for a normal population distribution. |
## Not run: fitprecision(interval=c(60, 70), propvals=c(0.2, 0.4), trans = "log") ## End(Not run)
## Not run: fitprecision(interval=c(60, 70), propvals=c(0.2, 0.4), trans = "log") ## End(Not run)
Renders an Rmarkdown document to display the density function of each fitted distribution, the parameter values, and the R command required to sample from each distribution.
generateReport( fit, output_format = "html_document", sf = 3, expert = 1, view = TRUE, clean = TRUE )
generateReport( fit, output_format = "html_document", sf = 3, expert = 1, view = TRUE, clean = TRUE )
fit |
An object of class |
output_format |
the output format for the document. One of |
sf |
number of significant figures to be displayed for the fitted parameters. |
expert |
if the |
view |
set to |
clean |
set to |
## Not run: # One expert, with elicited probabilities # P(X<20)=0.25, P(X<30)=0.5, P(X<50)=0.75 # and X>0. v <- c(20,30,50) p <- c(0.25,0.5,0.75) myfit <- fitdist(vals=v, probs=p, lower=0) generateReport(myfit) ## End(Not run)
## Not run: # One expert, with elicited probabilities # P(X<20)=0.25, P(X<30)=0.5, P(X<50)=0.75 # and X>0. v <- c(20,30,50) p <- c(0.25,0.5,0.75) myfit <- fitdist(vals=v, probs=p, lower=0) generateReport(myfit) ## End(Not run)
Takes an object of class elicitation
, evaluates a (weighted) linear pool,
and returns points on the density function at a sequence of values of the elicited
parameter
linearPoolDensity(fit, xl = -Inf, xu = Inf, d = "best", lpw = 1, nx = 200)
linearPoolDensity(fit, xl = -Inf, xu = Inf, d = "best", lpw = 1, nx = 200)
fit |
An object of class |
xl |
The lower limit in the sequence of parameter values. The default is the 0.001 quantile of the fitted distribution (or the 0.001 quantile of a fitted normal distribution, if a histogram fit is chosen). |
xu |
The upper limit in the sequence of parameter values. The default is the 0.999 quantile of the fitted distribution (or the 0.999 quantile of a fitted normal distribution, if a histogram fit is chosen). |
d |
The distribution fitted to each expert's probabilities. Options are
|
lpw |
A vector of weights to be used in linear pool, if unequal weighting is desired. |
nx |
The number of points in the sequence from |
A list, with elements
x |
a sequence of values for the uncertain parameter |
fx |
the density function of the linear pool, evaluated at each element in |
Jeremy Oakley <[email protected]>
## Not run: # Two experts # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) linearPoolDensity(myfit) ## End(Not run)
## Not run: # Two experts # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) linearPoolDensity(myfit) ## End(Not run)
Plots the elicited cumulative probabilities and, optionally, a fitted CDF. Elicited are shown as filled circles, and limits are shown as clear circles.
makeCDFPlot( lower, v, p, upper, fontsize = 12, fit = NULL, dist = NULL, showFittedCDF = FALSE, showQuantiles = FALSE, ql = 0.05, qu = 0.95, ex = 1, sf = 3, xaxisLower = lower, xaxisUpper = upper, xlab = "x", ylab = expression(P(X <= x)) )
makeCDFPlot( lower, v, p, upper, fontsize = 12, fit = NULL, dist = NULL, showFittedCDF = FALSE, showQuantiles = FALSE, ql = 0.05, qu = 0.95, ex = 1, sf = 3, xaxisLower = lower, xaxisUpper = upper, xlab = "x", ylab = expression(P(X <= x)) )
lower |
lower limit for the uncertain quantity |
v |
vector of values, for each value x in Pr(X<=x) = p in the set of elicited probabilities |
p |
vector of probabilities, for each value p in Pr(X<=x) = p in the set of elicited probabilities |
upper |
upper limit for the uncertain quantity |
fontsize |
font size to be used in the plot |
fit |
object of class |
dist |
the fitted distribution to be plotted. Options are
|
showFittedCDF |
logical. Should a fitted distribution function be displayed? |
showQuantiles |
logical. Should quantiles from the fitted distribution function be displayed? |
ql |
a lower quantile to be displayed. |
qu |
an upper quantile to be displayed. |
ex |
if the object |
sf |
number of significant figures to be displayed. |
xaxisLower |
lower limit for the x-axis. |
xaxisUpper |
upper limit for the x-axis. |
xlab |
x-axis label. |
ylab |
y-axis label. |
## Not run: vQuartiles <- c(30, 35, 45) pQuartiles<- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = vQuartiles, probs = pQuartiles, lower = 0) makeCDFPlot(lower = 0, v = vQuartiles, p = pQuartiles, upper = 100, fit = myfit, dist = "gamma", showFittedCDF = TRUE, showQuantiles = TRUE) ## End(Not run)
## Not run: vQuartiles <- c(30, 35, 45) pQuartiles<- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = vQuartiles, probs = pQuartiles, lower = 0) makeCDFPlot(lower = 0, v = vQuartiles, p = pQuartiles, upper = 100, fit = myfit, dist = "gamma", showFittedCDF = TRUE, showQuantiles = TRUE) ## End(Not run)
Plot fitted population pdfs at combinations of two different values of the population mean and variance.
pdfplots( medianfit, precisionfit, alpha = 0.05, tails = 0.05, lower = NA, upper = NA, n.x = 100, d = "best", fontsize = 18 )
pdfplots( medianfit, precisionfit, alpha = 0.05, tails = 0.05, lower = NA, upper = NA, n.x = 100, d = "best", fontsize = 18 )
medianfit |
The output of a |
precisionfit |
The output of a |
alpha |
Value between 0 and 1 to determine choice of means and variances used in plots |
tails |
Value between 0 and 1 to determine the tail area shown in the pdf plots |
lower |
lower limit on the x-axis for plotting. |
upper |
upper limit on the x-axis for plotting. |
n.x |
The number of points on the x-axis at which the pdf is plotted. |
d |
The fitted distribution for the population median. Can be one of "normal", "lognormal" or "best", where "best" will select the best fitting out of normal and lognormal. |
fontsize |
Font size used in the plots. |
Four pdfs are plotted, using each combination of the alpha
/2 and 1-alpha
/2
quantiles of the fitted distributions for the population median and standard deviation
A plot and a list, containing
mu |
The two population mean values used in the plots. |
sigma |
The two population standard deviation values used in the plots. |
multiplot
function obtained from
http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
## Not run: prfit <- fitprecision(interval = c(60, 70), propvals = c(0.2, 0.4), trans = "log") medianfit <- fitdist(vals = c(50, 60, 70), probs = c(0.05, 0.5, 0.95), lower = 0) pdfplots(medianfit, prfit, alpha = 0.01) ## End(Not run)
## Not run: prfit <- fitprecision(interval = c(60, 70), propvals = c(0.2, 0.4), trans = "log") medianfit <- fitdist(vals = c(50, 60, 70), probs = c(0.05, 0.5, 0.95), lower = 0) pdfplots(medianfit, prfit, alpha = 0.01) ## End(Not run)
Calculates a linear pool given a set of elicited judgements in a fit
object. Then calculates required probabilities or quantiles from the pooled
cumulative distribution function, or generates a random sample.
plinearpool(fit, x, d = "best", w = 1) qlinearpool(fit, q, d = "best", w = 1) rlinearpool(fit, n, d = "best", w = 1)
plinearpool(fit, x, d = "best", w = 1) qlinearpool(fit, q, d = "best", w = 1) rlinearpool(fit, n, d = "best", w = 1)
fit |
The output of a |
x |
A vector of required cumulative probabilities P(X<=x) |
d |
Scalar or vector of distributions to use for each expert.
Options for each vector element are |
w |
A vector of weights to be used in the weighted linear pool. |
q |
A vector of required quantiles |
n |
Number of random samples from the linear pool |
Quantiles are calculate by first calculating the pooled cumulative distribution function at 100 points, and then using linear interpolation to invert the CDF.
A probability or quantile, calculate from a (weighted) linear pool (arithmetic mean) of the experts' individual fitted probability.
Jeremy Oakley <[email protected]>
## Not run: # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) plinearpool(myfit, x=c(20, 50, 80)) qlinearpool(myfit, q=c(0.05, 0.5, 0.95)) # give more weight to first expert plinearpool(myfit, x=c(20, 50, 80), w=c(0.7, 0.3)) # force the use of gamma distributions for each expert qlinearpool(myfit, q=c(0.05, 0.5, 0.95), d="gamma") ## End(Not run)
## Not run: # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) plinearpool(myfit, x=c(20, 50, 80)) qlinearpool(myfit, q=c(0.05, 0.5, 0.95)) # give more weight to first expert plinearpool(myfit, x=c(20, 50, 80), w=c(0.7, 0.3)) # force the use of gamma distributions for each expert qlinearpool(myfit, q=c(0.05, 0.5, 0.95), d="gamma") ## End(Not run)
Plots kernel density estimates of the target variable, conditional on
each of a set of specified values of the extension variable. The plot
makes use of the function ggridges::geom_density_ridges()
, and so
uses kernel density estimates rather than the exact conditional density
function.
plotConditionalDensities( y, fitX, yCP, xMed, medianY, link = "identity", dist = "best", N = 1e+05, xLimits = NULL, fs = 12 )
plotConditionalDensities( y, fitX, yCP, xMed, medianY, link = "identity", dist = "best", N = 1e+05, xLimits = NULL, fs = 12 )
y |
vector of values for the extension variable at which to condition on. |
fitX |
an object of class |
yCP |
vector of conditioning points for the extension variable. |
xMed |
vector of medians of the target variable, corresponding to
each value of the extension variable in |
medianY |
the median value of the extension variable. |
link |
link in the median function. One of |
dist |
choice of parametric distribution for the c-distribution. Options are
|
N |
sample size used in the kernel density estimate |
xLimits |
x-axis limits |
fs |
font size |
## Not run: myfitX <- fitdist(vals = c(5.5, 9, 14), probs = c(0.25, 0.5, 0.75), lower = 0) plotConditionalDensities(y = c(2, 6, 10), fitX = myfitX, yCP = c(3, 5, 7, 9.5, 13.5), xMed = c(2, 6.5, 9, 13, 20), medianY = 7, link = "log", dist = "lognormal", xLimits = c(0, 60)) # Example with the logit link myfitXlogit <- fitdist(vals = c(0.2, 0.25, 0.3), probs = c(0.25, 0.5, 0.75), lower = 0, upper = 1) plotConditionalDensities(y = c(2, 6, 10), fitX = myfitXlogit, yCP = c(2, 4, 6, 8, 10), xMed = c(0.1, 0.3, 0.5, 0.7, 0.9), medianY = 6, link = "logit", dist = "beta") ## End(Not run)
## Not run: myfitX <- fitdist(vals = c(5.5, 9, 14), probs = c(0.25, 0.5, 0.75), lower = 0) plotConditionalDensities(y = c(2, 6, 10), fitX = myfitX, yCP = c(3, 5, 7, 9.5, 13.5), xMed = c(2, 6.5, 9, 13, 20), medianY = 7, link = "log", dist = "lognormal", xLimits = c(0, 60)) # Example with the logit link myfitXlogit <- fitdist(vals = c(0.2, 0.25, 0.3), probs = c(0.25, 0.5, 0.75), lower = 0, upper = 1) plotConditionalDensities(y = c(2, 6, 10), fitX = myfitXlogit, yCP = c(2, 4, 6, 8, 10), xMed = c(0.1, 0.3, 0.5, 0.7, 0.9), medianY = 6, link = "logit", dist = "beta") ## End(Not run)
Produces a plot of the conditional median function, given a set of conditioning points for the extension variable, a set of corresponding medians of the target variable, given the extension variable, and a choice of link. The identity link is the default, a log link can be used for non-negative target variables, and a logit link can be used for target variables constrained to lie between 0 and 1.
plotConditionalMedianFunction( yCP, xMed, yLimits = NULL, link = "identity", xlab = "Y", ylab = "median of X given Y", fs = 12, ybreaks = NULL, xbreaks = NULL )
plotConditionalMedianFunction( yCP, xMed, yLimits = NULL, link = "identity", xlab = "Y", ylab = "median of X given Y", fs = 12, ybreaks = NULL, xbreaks = NULL )
yCP |
vector of conditioning points for the extension variable. |
xMed |
vector of medians of the target variable, corresponding to
each value of the extension variable in |
yLimits |
limits for the extension variable, used to set the axis limits in the plot |
link |
link in the median function. One of |
xlab |
x-axis label |
ylab |
y-axis label |
fs |
font size |
ybreaks |
tick marks on the y-axis |
xbreaks |
tick marks on the axis |
Jeremy Oakley <[email protected]>
## Not run: plotConditionalMedianFunction(yCP = c(3, 5, 7, 9.5, 13.5), xMed = c(2, 6.5, 9, 13, 20), yLimits = c(0, 20), link = "log") plotConditionalMedianFunction(yCP = c(2, 4, 6, 8, 10), xMed = c(0.1, 0.3, 0.5, 0.7, 0.9), yLimits = c(0, 15), link = "logit") ## End(Not run)
## Not run: plotConditionalMedianFunction(yCP = c(3, 5, 7, 9.5, 13.5), xMed = c(2, 6.5, 9, 13, 20), yLimits = c(0, 20), link = "log") plotConditionalMedianFunction(yCP = c(2, 4, 6, 8, 10), xMed = c(0.1, 0.3, 0.5, 0.7, 0.9), yLimits = c(0, 15), link = "logit") ## End(Not run)
Plots the fitted density function for one or more experts. Can also plot a fitted linear pool if more than one expert. If plotting the density function of one expert, or the linear pool only, can also indicated desired lower and upper fitted quantiles.
plotfit( fit, d = "best", xl = -Inf, xu = Inf, yl = 0, yu = NA, ql = NA, qu = NA, lp = FALSE, ex = NA, sf = 3, ind = TRUE, lpw = 1, fs = 12, lwd = 1, xlab = "x", ylab = expression(f[X](x)), legend_full = TRUE, percentages = FALSE, returnPlot = FALSE, showPlot = TRUE )
plotfit( fit, d = "best", xl = -Inf, xu = Inf, yl = 0, yu = NA, ql = NA, qu = NA, lp = FALSE, ex = NA, sf = 3, ind = TRUE, lpw = 1, fs = 12, lwd = 1, xlab = "x", ylab = expression(f[X](x)), legend_full = TRUE, percentages = FALSE, returnPlot = FALSE, showPlot = TRUE )
fit |
An object of class |
d |
The distribution fitted to each expert's probabilities. Options are
|
xl |
The lower limit for the x-axis. The default is the 0.001 quantile of the fitted distribution (or the 0.001 quantile of a fitted normal distribution, if a histogram fit is chosen). |
xu |
The upper limit for the x-axis. The default is the 0.999 quantile of the fitted distribution (or the 0.999 quantile of a fitted normal distribution, if a histogram fit is chosen). |
yl |
The lower limit for the y-axis. Default value is 0. |
yu |
The upper limit for the y-axis. Will be set automatically if not specified. |
ql |
A lower quantile to be indicated on the density function plot. Only displayed when plotting the density function for a single expert. |
qu |
An upper quantile to be indicated on the density function plot. Only displayed when plotting the density function for a single expert. |
lp |
For multiple experts, set |
ex |
If judgements have been elicited from multiple experts, but a density plot for one expert only is required, the expert to be used in the plot. |
sf |
The number of significant figures to be displayed for the parameter values. |
ind |
If plotting a linear pool, set |
lpw |
A vector of weights to be used in linear pool, if unequal weighting is desired. |
fs |
The font size used in the plot. |
lwd |
The line width used in the plot. |
xlab |
A string or expression giving the x-axis label. |
ylab |
A string or expression giving the y-axis label. |
legend_full |
If plotting a linear pool, set |
percentages |
Set to |
returnPlot |
Set to |
showPlot |
Set to |
Jeremy Oakley <[email protected]>
## Not run: # Two experts # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) # Plot both fitted densities, using the best fitted distribution plotfit(myfit) # Plot a fitted beta distribution for expert 2, and show 5th and 95th percentiles plotfit(myfit, d = "beta", ql = 0.05, qu = 0.95, ex = 2) # Plot a linear pool, giving double weight to expert 1 plotfit(myfit, lp = T, lpw = c(2,1)) # Plot a linear pool, giving double weight to expert 1, # show 5th and 95th percentiles, surpress plotting of individual distributions, # and force use of Beta distributions plotfit(myfit, d = "beta", lp = T, lpw = c(2,1), ql = 0.05, qu = 0.95, ind=FALSE ) ## End(Not run)
## Not run: # Two experts # Expert 1 states P(X<30)=0.25, P(X<40)=0.5, P(X<50)=0.75 # Expert 2 states P(X<20)=0.25, P(X<25)=0.5, P(X<35)=0.75 # Both experts state 0<X<100. v <- matrix(c(30, 40, 50, 20, 25, 35), 3, 2) p <- c(0.25, 0.5, 0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) # Plot both fitted densities, using the best fitted distribution plotfit(myfit) # Plot a fitted beta distribution for expert 2, and show 5th and 95th percentiles plotfit(myfit, d = "beta", ql = 0.05, qu = 0.95, ex = 2) # Plot a linear pool, giving double weight to expert 1 plotfit(myfit, lp = T, lpw = c(2,1)) # Plot a linear pool, giving double weight to expert 1, # show 5th and 95th percentiles, surpress plotting of individual distributions, # and force use of Beta distributions plotfit(myfit, d = "beta", lp = T, lpw = c(2,1), ql = 0.05, qu = 0.95, ind=FALSE ) ## End(Not run)
Displays a horizontal bar for each expert, to represent the expert's plausible range. The coloured sections indicate the experts' quartiles: four intervals judged by the expert to be equally likely. The experts' medians are shown as dashed lines.
plotQuartiles( vals, lower, upper, fs = 12, expertnames = NULL, xl = NULL, xlabel = "X" )
plotQuartiles( vals, lower, upper, fs = 12, expertnames = NULL, xl = NULL, xlabel = "X" )
vals |
a matrix of elicited quartiles and medians: one column per expert, first row is the 25th percentile, 2nd row is the median, last row is the 75th percentile. |
lower |
a vector of lower plausible limits: one per expert |
upper |
a vector of upper plausible limits: one per expert |
fs |
font size to be used in the plot |
expertnames |
vector of experts' names |
xl |
vector of limits for x-axis |
xlabel |
x-axis label |
Jeremy Oakley <[email protected]>
## Not run: l <- c(2, 1, 5, 1) u <- c(95, 90, 65, 40) v <- matrix(c(15, 25, 40, 10, 20, 40, 10, 15, 25, 5, 10, 20), 3, 4) plotQuartiles(vals = v, lower = l, upper = u) ## End(Not run)
## Not run: l <- c(2, 1, 5, 1) u <- c(95, 90, 65, 40) v <- matrix(c(15, 25, 40, 10, 20, 40, 10, 15, 25, 5, 10, 20), 3, 4) plotQuartiles(vals = v, lower = l, upper = u) ## End(Not run)
Displays a horizontal bar for each expert, to represent the expert's plausible range. The coloured sections indicate the experts' tertiles: three intervals judged by the expert to be equally likely. The experts' medians are shown as dashed lines.
plotTertiles( vals, lower, upper, fs = 12, percentages = FALSE, expertnames = NULL, xl = NULL, xlabel = "X" )
plotTertiles( vals, lower, upper, fs = 12, percentages = FALSE, expertnames = NULL, xl = NULL, xlabel = "X" )
vals |
a matrix of elicited tertiles and medians: one column per expert, first row is the 33rd percentile, 2nd row is the median, last row is the 66th percentile. |
lower |
a vector of lower plausible limits: one per expert |
upper |
a vector of upper plausible limits: one per expert |
fs |
font size to be used in the plot |
percentages |
set to |
expertnames |
vector of experts' names |
xl |
vector of limits for x-axis |
xlabel |
x-axis label |
Jeremy Oakley <[email protected]>
## Not run: l <- c(-5, 0, 5, -10) u <- c(15, 35, 50, 35) v <- matrix(c(5, 8, 10, 10, 15, 20, 15, 18, 25, 10, 20, 30), 3, 4) plotTertiles(vals = v, lower = l, upper = u) ## End(Not run)
## Not run: l <- c(-5, 0, 5, -10) u <- c(15, 35, 50, 35) v <- matrix(c(5, 8, 10, 10, 15, 20, 15, 18, 25, 10, 20, 30), 3, 4) plotTertiles(vals = v, lower = l, upper = u) ## End(Not run)
Generates a random sample from all distributions specified
within an object of class elicitation
sampleFit(fit, n, expert = 1)
sampleFit(fit, n, expert = 1)
fit |
An object of class elicitation |
n |
The required sample size for each elicitation |
expert |
Specify which expert's distributions to sample from, if multiple experts' judgements have been elicited. |
A matrix of sampled values, one column per distribution. Column names are given to label the distributions.
## Not run: v <- c(20,30,50) p <- c(0.25,0.5,0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) sampleFit(myfit, n = 10) ## End(Not run)
## Not run: v <- c(20,30,50) p <- c(0.25,0.5,0.75) myfit <- fitdist(vals = v, probs = p, lower = 0, upper = 100) sampleFit(myfit, n = 10) ## End(Not run)
As part of the Extension Method, this function will generate a random sample from the marginal distribution of the target variable, using a sample from the marginal distribution of the extension variable, the specified c-distribution, and the appropriate judgements used to construct the median model.
sampleMarginalFit( fitX, sampleY, medianY, yCP, xMed, dist = "best", link = "identity" )
sampleMarginalFit( fitX, sampleY, medianY, yCP, xMed, dist = "best", link = "identity" )
fitX |
an object of class |
sampleY |
a sample from the marginal distribution of the extension variable. |
medianY |
the median value of the extension variable. |
yCP |
vector of conditioning points for the extension variable. |
xMed |
vector of medians of the target variable, corresponding to
each value of the extension variable in |
dist |
choice of parametric distribution for the c-distribution. Options are
|
link |
link in the median function. One of |
a vector containing a sample from the marginal distribution of the target variable.
## Not run: myfitX <- fitdist(vals = c(5.5, 9, 14), probs = c(0.25, 0.5, 0.75), lower = 0) ry <- rgamma(10, 5.19, 0.694) sampleMarginalFit(fitX = myfitX, sampleY = ry, medianY = 7, yCP = c(3, 5, 7, 9.5, 13.5), xMed = c(2, 6.5, 9, 13, 20), dist = "lognormal", link = "log") ## End(Not run)
## Not run: myfitX <- fitdist(vals = c(5.5, 9, 14), probs = c(0.25, 0.5, 0.75), lower = 0) ry <- rgamma(10, 5.19, 0.694) sampleMarginalFit(fitX = myfitX, sampleY = ry, medianY = 7, yCP = c(3, 5, 7, 9.5, 13.5), xMed = c(2, 6.5, 9, 13, 20), dist = "lognormal", link = "log") ## End(Not run)
Fits seven parametric models to an individual patient survival data set (using the flexsurv
package),
displays extrapolations, and report the time point at which there is the
widest range in estimated extrapolated survival probabilities. This function is intended to be used
only as an informal exploratory tool to support elicitation for survival extrapolation,
specifically, to inform the choice of target extrapolation time. The fitted models
are exponential, weibull, gamma, gompertz, log logistic, log normal and geneneralised gamma.
survivalModelExtrapolations( survDf, tOffset = 0, tEnd, group, tTruncate = NULL, dists = c("exp", "weibull", "gamma", "gompertz", "llogis", "lnorm", "gengamma"), nModels = length(dists), showPlot = TRUE )
survivalModelExtrapolations( survDf, tOffset = 0, tEnd, group, tTruncate = NULL, dists = c("exp", "weibull", "gamma", "gompertz", "llogis", "lnorm", "gengamma"), nModels = length(dists), showPlot = TRUE )
survDf |
data frame with individual patient data. Require to be a .csv file with three columns: "time", "event" and "treatment" (in that order). Values in the "event" column should be 0 for a censored observation, and 1 otherwise. The"treatment" column should be included even if there is only one treatment group.' |
tOffset |
discard observations with time less than this value, and fit survival
distributions to |
tEnd |
the maximum time point for extrapolation |
group |
character variable to select treatment group: one of the levels in the factor variable survDf$treatment |
tTruncate |
optional argument: time point at which to censor all observations |
dists |
character vector of distributions to fit. Default is |
nModels |
how many fitted models to plot, up to a maximum of 7, chosen by lowest AIC
value. Default is |
showPlot |
whether to display the plot |
A list containing the elements
KMplot |
a ggplot2 plot object; |
tMaxRange |
the time point at which there is the greatest difference between the largest and smallest extrapolated survival probability (if more than one distribution fitted); |
modelAIC |
the AIC for each fitted model. |
## Not run: # Make a data frame using the survival::veteran data frame sdf <- survival::veteran[, c("time", "status", "trt")] colnames(sdf) <- c("time", "event", "treatment") sdf$treatment <- factor(sdf$treatment, labels = c("standard", "test")) survivalModelExtrapolations(sdf, tEnd = 1000, group = "test", tTruncate = 100) ## End(Not run)
## Not run: # Make a data frame using the survival::veteran data frame sdf <- survival::veteran[, c("time", "status", "trt")] colnames(sdf) <- c("time", "event", "treatment") sdf$treatment <- factor(sdf$treatment, labels = c("standard", "test")) survivalModelExtrapolations(sdf, tEnd = 1000, group = "test", tTruncate = 100) ## End(Not run)
Provides a plot and approximate 95 extrapolated surival time, based on a assumption of constant hazard after some specified time. Intended to be used as part of the SHELF protocol for elicitation for survival extrapolation.
survivalScenario( tLower = 0, tUpper, expLower, expUpper, tTarget, survDf, groups = levels(survDf$treatment), expGroup = levels(survDf$treatment)[1], xl = "Time", fontsize = 12, showPlot = TRUE )
survivalScenario( tLower = 0, tUpper, expLower, expUpper, tTarget, survDf, groups = levels(survDf$treatment), expGroup = levels(survDf$treatment)[1], xl = "Time", fontsize = 12, showPlot = TRUE )
tLower |
lower limit for x-axis. |
tUpper |
upper limit for x-axis. |
expLower |
start time at which constant hazard is assumed. |
expUpper |
end time for using data to estimate constant hazard; data after this time will be censored. |
tTarget |
target extrapolation time. |
survDf |
data frame with individual patient data. Require to bea .csv file with three columns: "time", "event" and "treatment" (in that order). Values in the "event" column should be 0 for a censored observation, and 1 otherwise. The"treatment" column should be included even if there is only one treatment group.' |
groups |
character vector of names of the treatment group. Extracted from survDF by default. |
expGroup |
selected treatment group for extrapolating |
xl |
x-axis label |
fontsize |
plot fontsize |
showPlot |
whether to display the plot |
A list containing the elements
KMplot |
a ggplot2 plot object; |
interval |
an approximate 95 at the target extrapolation time. |
## Not run: sdf <- survival::veteran[, c("time", "status", "trt")] colnames(sdf) <- c("time", "event", "treatment") sdf$treatment <- factor(sdf$treatment, labels = c("standard", "test")) survivalScenario(tLower = 0,tUpper = 150, expLower = 100, expUpper = 150, tTarget = 250, survDf = sdf, expGroup = "standard") ## End(Not run)
## Not run: sdf <- survival::veteran[, c("time", "status", "trt")] colnames(sdf) <- c("time", "event", "treatment") sdf$treatment <- factor(sdf$treatment, labels = c("standard", "test")) survivalScenario(tLower = 0,tUpper = 150, expLower = 100, expUpper = 150, tTarget = 250, survDf = sdf, expGroup = "standard") ## End(Not run)