Title: | Bayesian Gower Agreement for Categorical Data |
---|---|
Description: | Provides tools for applying the Bayesian Gower agreement methodology (presented in the package vignette) to nominal or ordinal data. The framework can accommodate any number of units, any number of coders, and missingness; and can handle both one-way and two-way random study designs. Influential units and/or coders can be identified easily using leave-one-out statistics. |
Authors: | John Hughes [aut, cre] |
Maintainer: | John Hughes <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0-1 |
Built: | 2025-01-09 06:57:58 UTC |
Source: | CRAN |
Compute a credible interval for a Bayesian Gower fit.
## S3 method for class 'gower' confint(object, parm = "mu", level = 0.95, ...)
## S3 method for class 'gower' confint(object, parm = "mu", level = 0.95, ...)
object |
an object of class |
parm |
always ignored since there is only one parameter, mu. |
level |
the desired confidence level for the interval. The default is 0.95. |
... |
additional arguments. These are passed to |
This function computes a credible interval for mu, the agreement parameter.
This function uses the bootstrap sample to compute a credible interval. If type = "HPD"
is not an element of ..., the lower and upper limits of the interval are appropriate quantiles of the bootstrap sample. Otherwise the limits are for an HPD interval.
A vector with entries giving the lower and upper limits of the interval. These will be labelled as (1 - level) / 2 and 1 - (1 - level) / 2 if the quantile method was used. They will be labeled "Lower" and "Upper" if the interval is an HPD interval.
# Fit the liver data, using the mean distance for each row of the data matrix. # The range (which is equal to 4) must be passed to \code{\link{gower.agree}} # since these data are ordinal and the L1 distance function is used. We assume # a one-way sampling design for these data, i.e., units are random and coders # are fixed. Also compute a 95\% credible interval using the quantile method # and then the HPD method. data(liver) liver = as.matrix(liver) fit = gower.agree(liver, data.type = "ordinal", range = 4) confint(fit) confint(fit, type = "HPD")
# Fit the liver data, using the mean distance for each row of the data matrix. # The range (which is equal to 4) must be passed to \code{\link{gower.agree}} # since these data are ordinal and the L1 distance function is used. We assume # a one-way sampling design for these data, i.e., units are random and coders # are fixed. Also compute a 95\% credible interval using the quantile method # and then the HPD method. data(liver) liver = as.matrix(liver) fit = gower.agree(liver, data.type = "ordinal", range = 4) confint(fit) confint(fit, type = "HPD")
Apply the discrete metric to two scores.
discrete.dist(x, y)
discrete.dist(x, y)
x |
a score. |
y |
a score. |
This function applies the discrete metric to two scores. This is an appropriate distance function for nominal data.
0 if x
is equal to y
, 1 if x
is not equal to y
, NA
if either score is NA
.
Apply the Bayesian Gower agreement methodology to nominal or ordinal data.
gower.agree( data, data.type = c("nominal", "ordinal"), dist.type = c("mean", "max"), design = c("one-way", "two-way"), iter = 10000, ... )
gower.agree( data, data.type = c("nominal", "ordinal"), dist.type = c("mean", "max"), design = c("one-way", "two-way"), iter = 10000, ... )
data |
a matrix of scores. Each row corresponds to a unit, each column to a coder. |
data.type |
the type of scores to be analyzed, either |
dist.type |
for ordinal data, whether the row statistics are computed using the mean of the pairwise distances or the maximum pairwise distance. |
design |
the sampling design, either |
iter |
the desired size of the posterior sample. The default value is 10,000. |
... |
additional arguments for the distance function. These are ignored for nominal data. For ordinal data the range of the scores must be provided via argument |
This is the package's flagship function. It applies the Bayesian Gower methodology to nominal or ordinal data, and provides an estimate of the posterior mean along with a credible interval.
Function gower.agree
returns an object of class "gower"
, which is a list comprising the following elements.
mu.hat |
the estimate of the posterior mean. |
mu.sample |
the posterior sample. |
call |
the matched call. |
units |
the number of units. |
coders |
the number of coders. |
data |
the data matrix, sans rows that were removed due to missigness. |
data.type |
the type of scores, nominal or ordinal. |
dist.type |
for ordinal data, the manner in which the row statistics were computed. |
design |
the sampling design, one-way or two-way. |
row.stats |
the vector of row statistics. |
del |
the number of rows that were deleted due to missingness. |
# Fit the liver data, using the mean distance for each row of the data matrix. # The range (which is equal to 4) must be passed to \code{\link{gower.agree}} # since these data are ordinal and the L1 distance function is used. We assume # a one-way sampling design for these data, i.e., units are random and coders # are fixed. data(liver) liver = as.matrix(liver) fit = gower.agree(liver, data.type = "ordinal", range = 4) summary(fit)
# Fit the liver data, using the mean distance for each row of the data matrix. # The range (which is equal to 4) must be passed to \code{\link{gower.agree}} # since these data are ordinal and the L1 distance function is used. We assume # a one-way sampling design for these data, i.e., units are random and coders # are fixed. data(liver) liver = as.matrix(liver) fit = gower.agree(liver, data.type = "ordinal", range = 4) summary(fit)
Compute a highest posterior density (HPD) interval.
hpd(x, alpha = 0.05)
hpd(x, alpha = 0.05)
x |
the posterior sample. |
alpha |
the desired significance level. |
This function uses a given posterior sample to compute an HPD interval at a given significance level.
A 2-vector containing the lower endpoint and the upper endpoint, respectively.
Compute DFBETAs for units and/or coders.
## S3 method for class 'gower' influence(model, units, coders, ...)
## S3 method for class 'gower' influence(model, units, coders, ...)
model |
a fitted model object, the result of a call to |
units |
a vector of integers. A DFBETA will be computed for each of the corresponding units. |
coders |
a vector of integers. A DFBETA will be computed for each of the corresponding coders. |
... |
additional arguments. These are ignored. |
This function computes DFBETAs for one or more units and/or one or more coders.
A list comprising at most four elements.
dfbeta.units |
a vector containing DFBETAs for the units specified via argument |
dfbeta.coders |
a vector containing DFBETAs for the coders specified via argument |
fits.units |
a list containing fit objects for the omitted units specified via argument |
fits.coders |
a list containing fit objects for the omitted coders specified via argument |
# Analyze nominal data previously considered by Krippendorff. # Assume a one-way design. Compute a DFBETA for unit 6, which # should be rather influential. kripp = matrix(c(1,2,3,3,2,1,4,1,2,NA,NA,NA, 1,2,3,3,2,2,4,1,2,5,NA,3, NA,3,3,3,2,3,4,2,2,5,1,NA, 1,2,3,3,2,4,4,1,2,5,1,NA), 12, 4) kripp set.seed(12) fit = gower.agree(kripp) summary(fit) inf = influence(fit, units = 6) # Report the DFBETA for unit 6 and the estimate of mu when unit 6 # is ommitted. inf$dfbeta.units fit$mu.hat - inf$dfbeta.units
# Analyze nominal data previously considered by Krippendorff. # Assume a one-way design. Compute a DFBETA for unit 6, which # should be rather influential. kripp = matrix(c(1,2,3,3,2,1,4,1,2,NA,NA,NA, 1,2,3,3,2,2,4,1,2,5,NA,3, NA,3,3,3,2,3,4,2,2,5,1,NA, 1,2,3,3,2,4,4,1,2,5,1,NA), 12, 4) kripp set.seed(12) fit = gower.agree(kripp) summary(fit) inf = influence(fit, units = 6) # Report the DFBETA for unit 6 and the estimate of mu when unit 6 # is ommitted. inf$dfbeta.units fit$mu.hat - inf$dfbeta.units
Apply the L1 distance function to two scores.
L1.dist(x, y, range)
L1.dist(x, y, range)
x |
a score. |
y |
a score. |
range |
the range of the scores, i.e., the difference between the maximum score and the minimum score. |
This function applies the L1 distance function to two scores. This is an appropriate distance function for ordinal data.
, where
is the range of the scores; or
NA
if either score is NA
.
This data frame has exactly four columns. The first two columns contain liver herniation grades assigned by the first radiologist, and the final two columns contain grades assigned by the second radiologist. Each radiologist graded each image twice so that intra-rater consistency can be assessed. The liver grades and their meanings are provided below.
data(liver)
data(liver)
A data frame having 47 rows and four columns
1. No herniation of the liver into the fetal chest
2. Less than half of the ipsilateral thorax is occupied by the fetal liver
3. Greater than half of the thorax is occupied by the fetal liver
4. The liver dome reaches the thoracic apex
5. The liver dome not only reaches the thoracic apex but also extends across the thoracic midline
Print a summary of a Bayesian Gower fit.
## S3 method for class 'gower' summary(object, conf.level = 0.95, digits = 4, ...)
## S3 method for class 'gower' summary(object, conf.level = 0.95, digits = 4, ...)
object |
an object of class |
conf.level |
the confidence level for the credible interval. The default is 0.95. |
digits |
the number of significant digits to display. The default is 4. |
... |
additional arguments. These are currently ignored. |
This function prints a summary of the fit.
A list containing various elements of the summary is returned invisibly, but this function should be called for its side effects.
# Fit the liver data, using the mean distance for each row of the data matrix. # The range (which is equal to 4) must be passed to \code{\link{gower.agree}} # since these data are ordinal and the L1 distance function is used. We assume # a one-way sampling design for these data, i.e., units are random and coders # are fixed. data(liver) liver = as.matrix(liver) fit = gower.agree(liver, data.type = "ordinal", range = 4) summary(fit)
# Fit the liver data, using the mean distance for each row of the data matrix. # The range (which is equal to 4) must be passed to \code{\link{gower.agree}} # since these data are ordinal and the L1 distance function is used. We assume # a one-way sampling design for these data, i.e., units are random and coders # are fixed. data(liver) liver = as.matrix(liver) fit = gower.agree(liver, data.type = "ordinal", range = 4) summary(fit)