I'm trying to run a lasso regression on my large dataset but I keep obtaining the following error messages:
**Error in if (is.null(np) | (np[2] <= 1)) stop("x should be a matrix with 2 or more columns") :
argument is of length zero**
**Error in elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian, :
(list) object cannot be coerced to type 'double'**
My dataset is information on a travel index (GTI) for determining 'safe' LGBT traveling. I'm trying to use the other variables in the dataset to fit a model to and predict the GTI. Here is the code I have used thus far:
gaydata <- read.csv(file = 'GayData.csv')
names(gaydata)[names(gaydata) == "Total"] <- "GTI"
lasso_1 = glmnet(GTI ~ Anti.Discrimination.Legislation + Marriage.Civil.Partnership + Adoption.Allowed +
Transgender.Rights + Intersex.3rd.Option + Equal.Age.of.Consent +
X.Conversion.Therapy + LGBT.Marketing + Religious.Influence +
HIV.Travel.Restrictions + Anti.Gay.Laws + Homosexuality.Illegal +
Pride.Banned + Locals.Hostile + Prosecution + Murders + Death.Sentences, data = gaydata)
OR
lasso_2 = glmnet(x=gaydata, y=gaydata$GTI, alpha=1)
Removing 'Country' since it is categorical data that may be causing an issue
gaydata = subset(gaydata, select = -Country)
Trying to identify what is causing "argument is of length zero" error
sapply(gaydata, is.null)
sapply(gaydata, is.factor)
sum(is.null(gaydata))
In my research in trying to find a solution to this issue, I've seen that nulls, incorrect column names, and issues with factor variables typically cause the error. However, my data does not have those problems so I'm lost. My data is a copy and paste from the