I have a data file named "geneexp.csv".
the data contains information about gene expression of three different cell types (CD4 and CD8, CD19) I want to classify cells by performing the nearest shrunken centroid classification of training data in which the threshold is chosen by cross-validation. I split the data (70% train and 30% test).
data = read.csv("geneexp.csv")
splitData <- function(data, trainRate) {
n <- dim(data)[1]
idxs <- sample(1:n, floor(trainRate*n))
train <- data[idxs,]
test <- data[-idxs,]
return (list(train = train, test = test))
}
split <- splitData(data, .7)
train <- split$train
test <- split$test
then with the use of pamr
package I tried to buid the following model and plot :
y <- train[[ncol(train)]]
x <- t(train[,-ncol(train)])
mydata <- list(
x = x,
y = as.factor(as.factor(y)),
geneid = as.character(1:nrow(x)),
genenames = rownames(x)
)
# Training and cross-validating threshold
model <- pamr.train(mydata)
cvmodel <- pamr.cv(model, mydata)
pamr.plotcv(cvmodel)
but I can't make it work. I get the following error:
Error in
contrasts<-
(*tmp*
, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
I have already transfer y to the factors. Can you help me? How can I fix it?
as.numeric(as.character(y))
this looks incredibly dangerous. What is iny
? can you dotable(y)
$\endgroup$