0
library(caret) 
library(mvtnorm)
library(ncvreg)
library(glmnet)
library(flare)
air <- read.csv(file = 'C:/Users/42stu/Downloads/AirI(1).csv', check.names = FALSE, stringsAsFactors = FALSE)

for(x in 1:nrow(air)){
for (y in 1:ncol(air)){
air[x, y] <- as.numeric(air[x,y])
if(!is.numeric(air[x, y])){
print(x)
print(y)
}
}
}

air_shuffled <- air[sample(nrow(air)),]
dataset <- air_shuffled 

folds <- cut(seq(1,nrow(dataset)),breaks=10,labels=FALSE)

for(i in 1:10){
    testIndexes <- which(folds==i,arr.ind=TRUE)
    testData <- dataset[testIndexes,]
    testDatax <- testData[,2:ncol(testData)]
    testDatay <- testData[,1]

    trainData <- dataset[-testIndexes, ]
    trainDatax <- trainData[,2:ncol(trainData)]
    trainDatay <- t(trainData[,1])

    sqrt_lasso <- slim(trainDatax, trainDatay, method = "lq")


} 

My code is included above. I have converted everything to a numeric type; why am I still getting an error? Is there something wrong with the size of the matrices? Apologies if this isn't a good question; this is my first time posting on StackOverflow and my first semester using R.

  • I didn't see where you used `crossprod` in you code. From `slim`? – ThomasIsCoding Feb 23 '20 at 21:38
  • I don't use ```crossprod``` directly, but when I run the code, that's the error I receive. I believe it is used in the calculations for ```slim```. – user12950143 Feb 23 '20 at 21:44
  • what are the dimensions of `trainDatax` and `trainDatay`? – ThomasIsCoding Feb 23 '20 at 21:46
  • 2
    Hi user12950143.Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and how to give a [minimale reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). That way you can help others to help you! – dario Feb 23 '20 at 23:00
  • The error probably happens because you are passing `t(trainData[,1]`) as your `Y` response variable, which makes `Y` be a matrix of size `1xn` where `n` is the number of rows in your data. (In fact, check the output of `class(t(trainData[,1]))` which should return `matrix` compared to `class(trainData[,1])` which should return `numeric`). This makes the sizes of input arguments `X` and `Y` incompatible (`nxd` and `1xn` instead of `nxd` and `nx1`, respectively). So, I would suggest just trying to define `trainDatay <- trainData[,1]` as you do above with `testDatay` and run the program again. – mastropi Feb 24 '20 at 07:24

0 Answers0