[R] skip the error to continue the logistic regression in a loop

Juliet Hannah juliet.hannah at gmail.com
Sat Jul 4 18:19:07 CEST 2009


Here are two things to try.

First check the data.  There may be a factor that does not have
variation in the sample. For example,
if you had a predictor such as 'present'/'absent', in the current
sample, all of them
may be 'present'.

Second, you can put a 'try' statement in your function.


try( myglm <- glm(Response ~ Predictor, family=binomial, data=myData) )

See ?try.


On Thu, Jul 2, 2009 at 2:48 PM, Suyan Tian<stian at mail.rockefeller.edu> wrote:
> Hi, everyone:
>
> I am running logistic regression on a bunch of variables using apply
> command. But an error occurs, the whole process stops. I am wondering if
> anyone knows how to skip this error  and to continue the regression for the
> rest of variable.
>
> What I did is that first confine a function to the logistic regression, then
> use
>
> apply(data, 2, reg.fun)
>
> Then I got an error which is
>
> [1] "The result of logistic regression:"
> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
>  contrasts can be applied only to factors with 2 or more levels
>
> Can anyone help me out? Thanks a lot.
>
>
> Suyan
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list