Error In Predict.lmx Subscript Out Of Bounds
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have error in object$tables[[v]][, nd] : subscript out of bounds in r Meta Discuss the workings and policies of this site About Us
Naive Bayes Subscript Out Of Bounds
Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with naivebayes in r us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R segmented regression predict gives error: “subscript out of bounds” up vote 1 down vote favorite I'm building a segmented regression model using R's Segmented package. I was able to create the model but have trouble using the predict.segmented function. It always throws an error saying "subscript out of bounds" This is the exact error message: Error in newdata[[nameZ[i]]] : subscript out of bounds Traceback just gives this: 1: predict.segmented(seg_model, xtest) I created a simple case that gives the same error: require(segmented) x = c(1:90, 991:1000) y = c((x[1:10]/2), (x[11:100]*2)) lm_model = lm(y~x) seg_model = segmented(lm_model, seg.Z=~x, psi=list(x=NA), control=seg.control(display=FALSE, K=1, random=TRUE)) xtest = c(1:1000) predict.segmented(seg_model, xtest) I am starting to think this could be a bug. I'm new to R and not sure how to debug this either. Any help is appreciated! r regression linear piecewise share|improve this question asked Jan 17 '15 at 7:16 Itoo Power 203 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted You are using predict.segemented incorrectly. Like nearly all the predict() functions, your newdata parameter should be a data.frame, not a vector. Also, it needs to have names that match the variables used in your regression. Try predict.segmented(seg_model, data.frame(x=xtest)) instead. When using a function for the first
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bayes predict, subscript out of bounds up vote 5 down vote favorite I'm having some problems with the http://stackoverflow.com/questions/27997179/r-segmented-regression-predict-gives-error-subscript-out-of-bounds predict function when using bayesglm. I've read some posts that say this problem may arise when the out of sample data has more levels than the in sample data, but I'm using the same data for the fit and predict functions. Predict works fine with regular glm, but not with bayesglm. Example: control <- y ~ x1 + x2 # this works fine: glmObject <- glm(control, myData, family = binomial()) predicted1 <- predict.glm(glmObject http://stackoverflow.com/questions/24247745/bayes-predict-subscript-out-of-bounds , myData, type = "response") # this gives an error: bayesglmObject <- bayesglm(control, myData, family = binomial()) predicted2 <- predict.bayesglm(bayesglmObject , myData, type = "response") Error in X[, piv, drop = FALSE] : subscript out of bounds # Edit... I just discovered this works. # Should I be concerned about using these results? # Not sure why is fails when I specify the dataset predicted3 <- predict(bayesglmObject, type = "response") Can't figure out how to predict with a bayesglm object. Any ideas? Thanks! r prediction glm predict bayesglm share|improve this question edited Jun 16 '14 at 17:17 asked Jun 16 '14 at 15:57 Clark Henry 5351726 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted One of the reasons could be to do with the default setting for the parameter "drop.unused.levels" in the bayesglm command. By default, this parameter is set to TRUE. So if there are unused levels, it gets dropped during model building. However, the predict function still uses the original data with the unused levels present in the factor variable. This causes differences in level between the data used for model building and the one used for prediction (even it is the same data fame -in your case, myData). I have given an example below: n