Error inmatrix : Non-numeric matrix Extent - r

I was trying to run GSA(Gene Set enrichment Analysis) function in R using the Biobase package: Expression Set.
I was using the resp.type to be "Two class unpaired" .But when i run the function :
gsa <- GSA(x=exprs(Eset), genesets=genesets, genenames=genenames, y = as.integer(factor), resp.type= "Two class unpaired", minsize=2,maxsize=500,nperms=500)
It gives me an error saying :
Error in matrix(1, nrow = n, ncol = 1) : non-numeric matrix extent
I dont know what this error means.I did mode(exprs(eset)),it gives me "numeric"
Can anybody tell me how to get rid of this problem?

Related

Error for create_slope_cs function in the leastcostpath package

guys! I encountered an error when creating a cost surface based on DEM data.
Adm1 <-
rgeoboundaries::geoboundaries(
country = "Austria",
adm_lvl = "adm0")
r <- get_elev_raster(Adm1,z=4)
cs <- create_slope_cs(dem = r, cost_function = 'tobler', neighbours = 16)
The error is like
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'extent': ‘srs’ is not a slot in class “BasicRaster”
I can run this code on my other laptop. So I think there's nothing wrong with my code. But do you know how to fix this?

Reproducing predict function in the svm method in R

I want to reproduce predict function in R. I found very nice example here How to reproduce predict.svm in R?, but it does not work on my data.
The difference is that I have four classes.
I receive error "Error in x - x1 : non-numeric argument to binary operator". After advice from MrFlick, I add as.numeric to all values (this change the error, so I check my original data table, and there where few non numeric values).
Right now, I have another error: "Error in f(y, m) : dims [product 3] do not match the length of object [6]"
My data are big, so I prepared some values to show you my problem.
library(e1071)
Cval =100
GammaVal=0.1
sp1a<-as.numeric(c("2.58","0","0","10.85","20.1","0","0","0","0","0","76.03","0","0","28.79","0","2.76","0","0","23.99","0"))
sp1b<-as.numeric(c("135.32","133.82","134.24","132.84","135.11","133.55","132.99","130.25","133.19","132.42","135.8","133.99","133.33","135.52","134.67","134.79","134.32","133.9","135.36","133.14"))
sp1c<-as.numeric(sp1b)/2.3
sp1d<-as.numeric(sp1b)-3.5
sp1e<-as.numeric(sp1a)+1.3
sp1f<-as.numeric(sp1a)*2
data<-data.frame(cbind(sp1a,sp1b,sp1c,sp1d,sp1e,sp1f,class=c(rep(1,4),rep(2,5),rep(3,5),rep(4,6))))
svm_mod = svm(class~.,type="C-classification",data=data,cost = Cval, gamma = GammaVal,cross=10)
summary(svm_mod)
svm_train_pred = predict(svm_mod, data)
self_check_svm_out = cbind(data,svm_train_pred)
tab <- table(pred = svm_train_pred, true = data[,7])
## my predict functions
k<-function(x,x1,gamma){
return(exp(-gamma*sum((x-x1)^2)))
}
f<-function(x,m){
return(t(m$coefs) %*% as.matrix(apply(m$SV,1,k,x,m$gamma)) - m$rho)
}
my.predict<-function(m,x){
apply(x,1,function(y) sign(f(y,m)))
}
table(my.predict(svm_mod,data[,1:4]),predict(svm_mod,data[,1:4]))

Error in pnbd.LL(params, x, t.x, T.cal) : T.cal must be numeric and may not contain negative numbers in BTYD in r

I am building a pareto/nbd model using BTYD package and I am getting error while using it.
I have been following the directions from [BTYD walkthrough][1]. Everything was working fine until I got to the calibration customer-by-sufficient-statistic matrix (cal.cbs). I used the following code to generate cal.cbs, as instructed in the tutorial:
library(BTYD)
tot.cbt <- dc.CreateFreqCBT(elog)
cal.cbt <- dc.MergeCustomers(tot.cbt, freq.cbt)
birth.periods <- split.data$cust.data$birth.per
last.dates <- split.data$cust.data$last.date
cal.cbs.dates <- data.frame(birth.periods, last.dates,
end.of.cal.period)
cal.cbs <- dc.BuildCBSFromCBTAndDates(cal.cbt, cal.cbs.dates,
per="month")
But I got a warning message:
In cbind(f, r, T) :
number of rows of result is not a multiple of vector length (arg 2)
Though I overcome the warning by using the following code:
tot.cbt <- dc.CreateFreqCBT(elog.cal)
# instead of
tot.cbt <- dc.CreateFreqCBT(elog)
But I am getting error message while estimating parameters:
params <- pnbd.EstimateParameters(cal.cbs)
Error in pnbd.LL(params, x, t.x, T.cal) :
T.cal must be numeric and may not contain negative numbers.
I have no clue how to fix this problem and why am I getting this error. Can anybody help me please? Many thanks in advance!
Make sure cal.cbs is a matrix, I had similar problem and this fixed it.
cal.cbs <- as.matrix(cal.cbs)

Predict() with regsubsets

I'm trying to replicate the results from An Introduction to Statistical Learning with Applications in R. Specifically, the Lab in section 6.5.3. I have followed the code in the lab exactly:
library("ISLR")
library("leaps")
set.seed(1)
train = sample(c(TRUE, FALSE), nrow(Hitters), rep = TRUE)
test = (!train)
regfit.best = regsubsets(Salary ~., data = Hitters[train,], nvmax= 19)
test.mat = model.matrix(Salary~., data = Hitters[test,])
val.errors = rep(NA, 19)
for (i in 1:19){
coefi= coef(regfit.best, id = i)
pred=test.mat[,names(coefi)]%*%coefi
val.errors[i]=mean((Hitters$Salary[test]-pred)^2)
}
When I run this I still get the following error:
Warning message:
In Hitters$Salary[test] - pred :
longer object length is not a multiple of shorter object length
Error in mean((Hitters$Salary[test] - pred)^2) :
error in evaluating the argument 'x' in selecting a method for function 'mean': Error: dims [product 121] do not match the length of object [148]
And val.errors is a vector of 19 NAs.
I'm still relatively new to R and to the validation approach, so I'm not sure exactly why the dimensions of these are different.
It was actually an issue with not carrying over steps from the previous subsection, which omitted entries that were incomplete.
You need to remove rows with missing data. Run "Hitters = na.omit(Hitters)" at the beginning.

Text Classification using Random Forest in R

Hi I'm new to R and want perform text message classification in R. Data contains 2 columns: "type":spam or ham and "message": character. I have performed data cleaning and converted data into Document Term Matrix
data_dtm <- DocumentTermMatrix(corpus, control = list(global = c(2, Inf)))
Now I want to use the Random forest classification:
sms_classifier <- randomForest(x= as.matrix(sms_dtm_train), y= train_data$type, ntree= 10)
sms_dtm_train: is the document term matrix of training data
This code is not working. Please tell me what is the problem?
This is the error message i am getting
Error in randomForest.default(x = as.matrix(sms_dtm_train), y = train_data$type, :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In storage.mode(x) <- "double" : NAs introduced by coercion

Resources