r - Error in Pearson correlation, 'y' must be numeric -


i'm running regression modelling glm between train , validation variables. variables in numeric values. there error when try run correlation error: 'y' must numeric..the code following:

data <- read.csv(file="fielddatabase.csv", sep=",", header=t) attach(data) summary(data)  ############################### ## prepare bootstrap samples ###############################  set.seed(550)  # create empty lists in subsets can stored train <- list() validation <- list()  # set bootstrap parameters n = length(data[,9]) # n° of observations b = 500             # n° of bootstrap iterations  # start loop for(i in 1:b){    # create random numbers replacement select samples each group   idx = sample(1:n, n, replace=true)    # select subsets of 5 groups based on random numbers   train[[i]] <- data[idx,]   validation[[i]] <- data[-idx,] }  ###################################### ## start regression modelling glm ###################################### # create empty lists in models accuracies can stored # total id.nb<-list() obs.nb<-list() pred.nb<-list() r2.nb<-list() rmse.nb<-list() nrmse.nb<-list() imp.nb<-list() bias.nb <- list()   # run glm for(i in 1:b)   train <- train[[i]]    validation <- validation[[i]]   len<-length( validation[,1])    # store , select observations   id<-validation$id   id.nb [[i]]<-id   obs <- validation[,2]   obs.nb[[i]]<-obs    # run glm using negative binomial family.     glm_total <- glm(biomass ~  hmax + nmax + hsd + hskewness + hkurtosis, data=train,  family=negative.binomial(theta=1 , link="log"))    # predict biomass values    pred<-stats:::predict(glm_total, newdata=validation, type="response")    # store model accuracies   pred.nb[[i]]<-pred   r2.nb[[i]]<-(cor(pred, obs, method="pearson"))^2 

here's error shows:

error in cor(pred, obs, method = "pearson") : 'y' must numeric 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -