I'm fitting a logistic regression model (with R
's caret
package) to data here. I aim to predict whether Hillary or Trump will win a given county.
The relevant code:
logisticSettings <- trainControl(method = "cv", number = 10, returnResamp = "all", classProbs = TRUE, summaryFunction = twoClassSummary)
logisticModel <- train(electTrain[,2:length(electTrain)], make.names(electTrain[,1]), method = "plr", metric = "ROC", trControl = logisticSettings)
electTrain
is my training dataset; the first column is the column of classes and the rest is features. When I run this, I get the following error:
Error in solve.default(ddf) :
system is computationally singular: reciprocal condition number = 9.55304e-17
I think this stems at least in part from the data being highly correlated. For example, one column is 2010 population, and another is 2010 population estimate. To remedy this, I removed some columns from my training set so that no features were correlated at above .92 (arbitrary cutoff).
But the error persists. What's wrong? Some ideas:
The error cutoff is still too high.
One column is approximately a linear combination of two or more others.
I've made a mistake in the code.