1
$\begingroup$

I would like to use cross-validation to test how predictive my mixed-effect logistic regression model is (model run with glmer). Is there an easy way to do this using a package in R? I've only seen cross validation functions in R for use with linear models.

$\endgroup$
7
  • 2
    $\begingroup$ This question appears to be off-topic because it is about asking for R packages / code. $\endgroup$ Commented Mar 1, 2014 at 17:39
  • 1
    $\begingroup$ Welcome to the site, @user1566200. If you are only asking about how to do this in R, this is be off-topic for CV (see our help center). R-based programming questions can be on-topic on Stack Overflow, but this isn't a programming question, & it lacks a reproducible example, so it would be off-topic on SO as well. The r-help-listserv might be a viable option. If you have a question about the substantive statistical issues here, please edit to clarify, else this may be closed. $\endgroup$ Commented Mar 1, 2014 at 17:43
  • $\begingroup$ Sorry! Didn't realize R package questions aren't allowed here. Where can I repost? $\endgroup$ Commented Mar 1, 2014 at 17:56
  • 1
    $\begingroup$ No need to apologize, it's an easy mistake. CV is a Q&A site for statistics (ML, data-viz., etc.) questions, not for how to use software. I would guess the best option would be the r-hlep-listserv, but it's not clear you will need to re-post. The answer for R is already given. $\endgroup$ Commented Mar 1, 2014 at 17:58
  • 1
    $\begingroup$ Also: stats.stackexchange.com/questions/18971/… may be relevant. $\endgroup$ Commented Mar 1, 2014 at 18:13

1 Answer 1

3
$\begingroup$

Check out the caret package. It has utilities to simplify building and comparing models based on really any arbitrary algorithm. The particular function in the package you are looking for is train.

This page gives a demo of how to fit a model using the train function with 10-fold cross-validation.

$\endgroup$
6
  • $\begingroup$ Thanks! Unfortunately I don't see glmer/Mixed Effects models as model options for train. $\endgroup$ Commented Mar 1, 2014 at 17:55
  • $\begingroup$ If you look at the documentation for the train function, you'll see it directs you to the following instructions on using train with user defined (or otherwise unsupported) models: caret.r-forge.r-project.org/custom_models.html $\endgroup$
    – David Marx
    Commented Mar 1, 2014 at 18:05
  • 2
    $\begingroup$ Is it possible to tell caret that there is a grouping/clustering in the data that must be taken into account when splitting the data - but that otherwise the splitting should be random? $\endgroup$ Commented Mar 1, 2014 at 18:08
  • $\begingroup$ Check out their page on data splitting. caret.r-forge.r-project.org/splitting.html $\endgroup$
    – David Marx
    Commented Mar 1, 2014 at 18:45
  • 1
    $\begingroup$ If I understand what you're asking: set up your grouping as a class variable, and then pass that classification to createDataPartition as described on that page. Maybe I don't understand what you're asking, but I'm fairly certain that page holds your answer. $\endgroup$
    – David Marx
    Commented Mar 1, 2014 at 21:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.