Search code examples
rmlogit

(list) object cannot be coerced in clogitLasso


I have a problem with the package clogitLasso where I continually get the error "(list) object cannot be coerced to type 'double'"

I've done plenty of searching on this, and there are plenty of ways to pre-convert the data to solve this problem, but no matter what I do it keeps coming up.

I'm not sure what I'm doing wrong here - I can generate data structured exactly like this within R and it runs with the same syntax without any problems, but when I read it in like this it doesn't work.

Using the data (trimmed, but gives the same error): https://pastebin.com/WfB1LJQ2

And the code:

library(clogitLasso)
#Read in data
data <- read.csv('data.txt',sep="\t")

#Data must be sorted so that the 
#binary=1 option comes FIRST within the strata
datasorted <- data[order(data$groupid,-data$binary),]

#Convert from a data frame to numericals
X <- as.matrix(datasorted[,1:4])
y <- as.numeric(datasorted[,5])
group <- as.numeric(datasorted[,6])

results <- clogitLasso(X,y,group)

This gives the same error every time. Any tips would be greatly appreciated!


Solution

  • The object y must be of class matrix. Here is the modified code:

    library(clogitLasso)
    data <- read.csv('WfB1LJQ2.txt',sep="\t", header=T)
    datasorted <- data[order(data$groupid,-data$binary),]
    X <- as.matrix(datasorted[,1:4])
    y <- as.matrix(datasorted[,5])
    group <- as.numeric(datasorted[,6]) 
    
    results <- clogitLasso(X,y,group)  
    plot(results)
    

    enter image description here