Welcome to R. I am also a STATA converter.
This is a difficult problem, but its answer is necessary for understanding. To understand why the predict function does not work for glmmML, you need to understand the S3 methods (see http://adv-r.had.co.nz/OO-essentials.html ).
Let me clarify a bit. R is an object oriented language. This means that everything in R is an object (i.e. Vector, function, data.frame). Each object contains attributes. An attribute is essentially metadata about the object itself. For example, variable names in data.frame are attributes. One attribute that all objects have is a class. To see the class of any object, just call the class() function.
Many, but not all, functions use S3 methods. The predict function is one of these functions. This means that when calling predict function scans the class of the object. Then, depending on the choice of class that another prediction function should use. For example, if your object is a class lm , the prediction function will call the predict.lm function. Other predict functions include: predict.glm for objects of class glm , predict.loess for objects of class loess , predict.nls for objects of class nls , etc. (For a complete list, read the predict help). Unfortunately, the predict.glmmML function predict.glmmML not exist. Therefore, when you call the predict function on an object of class glmmML , you get an error message.
id <- factor(rep(1:20, rep(5, 20))) y <- rbinom(100, prob = rep(runif(20), rep(5, 20)), size = 1) x <- rnorm(100) dat <- data.frame(y = y, x = x, id = id) fit.2 <- glmmML(y ~ x, data = dat, cluster = id) predict(fit.2) Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "glmmML" class(fit.2) [1] "glmmML"
The error is very informative. This basically suggests that R was trying to use S3 methods, but there wasn’t "expected.glmmML"
What about the mclogit function that user mclogit offers. We will see
data(Transport) fit <- mclogit( cbind(resp,suburb)~distance+cost, data=Transport ) class(fit) [1] "mclogit" "lm"
The fit class is mclogit and lm . Will predict work? Yes! When you call predict(fit) , the predict function first looks for predict.mclogit , which does not exist. Now he will search for predict.lm . What exists.