Skip to main content
. Author manuscript; available in PMC: 2016 Oct 25.
Published in final edited form as: Stat Med. 2010 Mar 15;29(6):617–626. doi: 10.1002/sim.3819

Table V.

Function in R for calculating the two-rater model-based kappa statistic and its variance.

twokappafn = function(sigma2u, beta1)
{
integrand1 = function(z)
  {
    term1=pnorm(sqrt(sigma2u)*z − beta1)
    term2= pnorm(sqrt(sigma2u)*z + beta1)
fullintegrand= term1*term2*dnorm(z)
}
result1 = integrate (integrand1, lower=−100, upper=100)
integrand2=function(z)
{
    term3=(1-pnorm(sqrt(sigma2u)*z − beta1))
    term4=(1-pnorm(sqrt(sigma2u)*z + beta1))
fullintegrand2=term3*term4*dnorm(z)
}
result2= integrate(integrand2, lower=−100, upper=100)
res2=result2 $value
# two-rater model-based kappa
2*(res1 + res2)−1
}
# Calculation of variance: need to enter values for varbeta1, varsigmasqu, sigmasqu and beta1.
integrand1a = function(z)
{term=(0.5*(1/sqrt(sigmasqu))*dnorm(sqrt(sigmasqu)*z + beta1/2)*pnorm(sqrt(sigmasqu)*z − beta1/2)
+ 0.5*(1/sqrt (sigmasqu))*pnorm(sqrt(sigmasqu)*z + beta1/2)*dnorm(sqrt(sigmasqu)*z − beta1/2))
*dnorm(z)*z }
result1a=integrate(integrand1a, lower=−100, upper=100)
integrand1b = function(z)
{term=(−0.5*(1/sqrt(sigmasqu))*dnorm(sqrt(sigmasqu)*z + beta1/2)*(1-pnorm(sqrt(sigmasqu)*z − beta1/2))*z
−0.5*(1/sqrt(sigmasqu))*pnorm(sqrt(sigmasqu)*z + beta1/2)*dnorm(sqrt(sigmasqu)*z − beta1/2))
*dnorm(z)*z}
result1b=integrate(integrand1b, lower=−100, upper=100)
vectorh1=result1a$value+result1b$value
integrand1b = function(z)
{term=(0.5*dnorm(sqrt(sigmasqu)*z + beta1/2)*pnorm(sqrt(sigmasqu)*z − beta1/2) − 0.5*pnorm(sqrt(sigmasqu)*z
+ beta1/2)*dnorm(sqrt(sigmasqu)*z − beta1/2))*dnorm(z)}
result2a=integrate(integrand2a, lower=−100, upper=100)
integrand2b = function(z)
{term=(−0.5*dnorm(sqrt(sigmasqu)*z + beta1/2)*(1-pnorm(sqrt(sigmasqu)*z − beta1/2))
+ 0.5*(1-pnorm(sqrt(sigmasqu)*z + beta1/2))*dnorm(sqrt(sigmasqu)*z − beta1/2))*dnorm(z)}
result2b=integrate(integrand2b, lower=−100, upper=100)
vectorh2=result2a$value+result2b$value
covarmat = matrix(c(varsigmasqu,0,0,varbeta1), ncol=2)
vectorh = c(vectorh1, vectorh2)
varkappam = 4*(vectorh %*% covarmat %*% vectorh)
}