Title: Psych package won't update: cohen.kappa function stuck on old version
Description
I'm trying to use the weights = "quadratic" argument in psych::cohen.kappa, which according to documentation should be available in recent versions of the psych package (>= 2.5.x). However, after repeated reinstallations, I still get the old function signature that does not accept weights:
function (x, w = NULL, n.obs = NULL, alpha = 0.05, levels = NULL, w.exp = 2)
What I've Tried
- Removed all
psychfolders from my R library path (C:/Users/vbholland/AppData/Local/Programs/R/R-4.5.0/library) - Verified
.libPaths()only points to the above directory - Installed psych from source:
install.packages("psych", type = "source") - Restarted R, RStudio, and my computer multiple times
- Checked
find.package("psych")andpackageVersion("psych")after install (shows version 2.5.6 in the correct path) - Ensured no workspace masking (checked with
ls()andfind("cohen.kappa")) - Used
detach("package:psych", unload = TRUE)before reloading
Output after install and load:
library(psych)
psych::cohen.kappa
# Output:
function (x, w = NULL, n.obs = NULL, alpha = 0.05, levels = NULL, w.exp = 2)
System Info
- R version: 4.5.0 (Windows 10)
- psych version: 2.5.6 (installed from source)
- Only one library path:
C:/Users/vbholland/AppData/Local/Programs/R/R-4.5.0/library - No other
psychfolders in any user or system library
Question
What could be causing R to load the old version of cohen.kappa after a fresh install?
Is there any hidden cache or environment variable I should clear?
Here is the output I get after multiple restarts and reinstalls of the "psych" package:
library(psych)
psych::cohen.kappa
function (x, w = NULL, n.obs = NULL, alpha = 0.05, levels = NULL,
w.exp = 2)
{
cl <- match.call()
p <- dim(x)[1]
len <- p
bad <- FALSE
if ((dim(x)[2] == p) || (dim(x)[2] < 3)) {
result <- cohen.kappa1(x, w = w, n.obs = n.obs, alpha = alpha,
levels = levels, w.exp = w.exp)
}
else {
nvar <- dim(x)[2]
ck <- matrix(NA, nvar, nvar)
if (!is.null(colnames(x))) {
colnames(ck) <- rownames(ck) <- colnames(x)
}
else {
colnames(ck) <- rownames(ck) <- paste("R", 1:nvar,
sep = "")
}
diag(ck) <- 1
result <- list(cohen.kappa = ck)
k <- 2
for (i in 2:nvar) {
for (j in 1:(i - 1)) {
x1 <- data.frame(x[, i], x[, j])
x1 <- na.omit(x1)
ck1 <- cohen.kappa1(x1, w = w, n.obs = n.obs,
alpha = alpha, levels = levels, w.exp = w.exp)
result[[paste(colnames(ck)[j], rownames(ck)[i])]] <- ck1
if (ck1$bad) {
warning("No variance detected in cells ", i,
" ", j)
bad <- TRUE
}
ck[i, j] <- result[[k]]$kappa
ck[j, i] <- result[[k]]$weighted.kappa
k <- k + 1
}
}
result[[1]] <- ck
av.kappa <- mean(ck[lower.tri(ck)], na.rm = TRUE)
av.wt <- mean(ck[upper.tri(ck)], na.rm = TRUE)
result$av.kappa <- av.kappa
result$av.wt <- av.wt
}
if (bad)
message("At least one item had no variance. Try describe(your.data) to find the problem.")
class(result) <- c("psych", "kappa")
return(result)
}
<bytecode: 0x000001cfebb95b80>
<environment: namespace:psych>
ls()
character(0)
rm(cohen.kappa)
Warning message:
In rm(cohen.kappa) : object 'cohen.kappa' not found
library(psych)
psych::cohen.kappa
function (x, w = NULL, n.obs = NULL, alpha = 0.05, levels = NULL,
w.exp = 2)
{
cl <- match.call()
p <- dim(x)[1]
len <- p
bad <- FALSE
if ((dim(x)[2] == p) || (dim(x)[2] < 3)) {
result <- cohen.kappa1(x, w = w, n.obs = n.obs, alpha = alpha,
levels = levels, w.exp = w.exp)
}
else {
nvar <- dim(x)[2]
ck <- matrix(NA, nvar, nvar)
if (!is.null(colnames(x))) {
colnames(ck) <- rownames(ck) <- colnames(x)
}
else {
colnames(ck) <- rownames(ck) <- paste("R", 1:nvar,
sep = "")
}
diag(ck) <- 1
result <- list(cohen.kappa = ck)
k <- 2
for (i in 2:nvar) {
for (j in 1:(i - 1)) {
x1 <- data.frame(x[, i], x[, j])
x1 <- na.omit(x1)
ck1 <- cohen.kappa1(x1, w = w, n.obs = n.obs,
alpha = alpha, levels = levels, w.exp = w.exp)
result[[paste(colnames(ck)[j], rownames(ck)[i])]] <- ck1
if (ck1$bad) {
warning("No variance detected in cells ", i,
" ", j)
bad <- TRUE
}
ck[i, j] <- result[[k]]$kappa
ck[j, i] <- result[[k]]$weighted.kappa
k <- k + 1
}
}
result[[1]] <- ck
av.kappa <- mean(ck[lower.tri(ck)], na.rm = TRUE)
av.wt <- mean(ck[upper.tri(ck)], na.rm = TRUE)
result$av.kappa <- av.kappa
result$av.wt <- av.wt
}
if (bad)
message("At least one item had no variance. Try describe(your.data) to find the problem.")
class(result) <- c("psych", "kappa")
return(result)
}
<bytecode: 0x000001cfebb95b80>
<environment: namespace:psych>
find("cohen.kappa")
[1] "package:psych"
detach("package:psych", unload = TRUE)
library(psych)
psych::cohen.kappa
function (x, w = NULL, n.obs = NULL, alpha = 0.05, levels = NULL,
w.exp = 2)
{
cl <- match.call()
p <- dim(x)[1]
len <- p
bad <- FALSE
if ((dim(x)[2] == p) || (dim(x)[2] < 3)) {
result <- cohen.kappa1(x, w = w, n.obs = n.obs, alpha = alpha,
levels = levels, w.exp = w.exp)
}
else {
nvar <- dim(x)[2]
ck <- matrix(NA, nvar, nvar)
if (!is.null(colnames(x))) {
colnames(ck) <- rownames(ck) <- colnames(x)
}
else {
colnames(ck) <- rownames(ck) <- paste("R", 1:nvar,
sep = "")
}
diag(ck) <- 1
result <- list(cohen.kappa = ck)
k <- 2
for (i in 2:nvar) {
for (j in 1:(i - 1)) {
x1 <- data.frame(x[, i], x[, j])
x1 <- na.omit(x1)
ck1 <- cohen.kappa1(x1, w = w, n.obs = n.obs,
alpha = alpha, levels = levels, w.exp = w.exp)
result[[paste(colnames(ck)[j], rownames(ck)[i])]] <- ck1
if (ck1$bad) {
warning("No variance detected in cells ", i,
" ", j)
bad <- TRUE
}
ck[i, j] <- result[[k]]$kappa
ck[j, i] <- result[[k]]$weighted.kappa
k <- k + 1
}
}
result[[1]] <- ck
av.kappa <- mean(ck[lower.tri(ck)], na.rm = TRUE)
av.wt <- mean(ck[upper.tri(ck)], na.rm = TRUE)
result$av.kappa <- av.kappa
result$av.wt <- av.wt
}
if (bad)
message("At least one item had no variance. Try describe(your.data) to find the problem.")
class(result) <- c("psych", "kappa")
return(result)
}
<bytecode: 0x000001cff7d9b9c8>
<environment: namespace:psych>
find.package("psych")
[1] "C:/Users/vbholland/AppData/Local/Programs/R/R-4.5.0/library/psych"
packageVersion("psych")
[1] ‘2.5.6’
Has anyone else encountered this issue?
Any help or suggestions appreciated! Thank you.