Grokbase Groups R r-help May 2012
FAQ

[R] R Error: System is computationally singular

Nathan Svoboda
May 24, 2012 at 5:57 pm
Greetings,

I am trying to fit a zero-inflated Poisson model using zeroinfl() from the
pscl library. I have 5 covariates (4 continuous, 1 categorical); the
categorical variable has 7 levels. I have had success fitting models that
contain only the continuous covariates; however, when I add the categorical
variable to any of the models (or if I run it by itself) I get the following
error:

Error in solve.default(as.matrix(fit$hessian)) :

system is computationally singular: reciprocal condition number =
3.46934e-20

The code I am using is:

library(pscl)
f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
D_GRASS)
ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

There is no correlation between my covariates. Also, I tried reducing my
categorical covariate to 3 levels and still receive the same error. Can
anyone suggest why I may be getting this error when I add the categorical
covariate?

I appreciate your time and input. Thank you,

Nate

Nathan Svoboda
Graduate Research Assistant
Carnivore Ecology Lab
Mississippi State University

--
View this message in context: http://r.789695.n4.nabble.com/R-Error-System-is-computationally-singular-tp4631242.html
Sent from the R help mailing list archive at Nabble.com.
reply

Search Discussions

7 responses

  • David Winsemius at May 24, 2012 at 6:54 pm

    On May 24, 2012, at 1:57 PM, Nathan Svoboda wrote:

    Greetings,

    I am trying to fit a zero-inflated Poisson model using zeroinfl()
    from the
    pscl library. I have 5 covariates (4 continuous, 1 categorical); the
    categorical variable has 7 levels. I have had success fitting
    models that
    contain only the continuous covariates; however, when I add the
    categorical
    variable to any of the models (or if I run it by itself) I get the
    following
    error:

    Error in solve.default(as.matrix(fit$hessian)) :

    system is computationally singular: reciprocal condition number =
    3.46934e-20

    The code I am using is:

    library(pscl)
    f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
    D_GRASS)
    ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

    There is no correlation between my covariates. Also, I tried
    reducing my
    categorical covariate to 3 levels and still receive the same error.
    Can
    anyone suggest why I may be getting this error when I add the
    categorical
    covariate?
    What does this show:

    with( FAWNS, table(LOCS, LCOVER) )

    --
    David Winsemius, MD
    West Hartford, CT
  • Nathan Svoboda at May 24, 2012 at 7:16 pm
    Thank you for your quick reply!

    When I run the code you provide I get this output:

    LCOVER
    LOCS 1 2 3 4 5 6 7 9
    0 214507 79939 69803 778359 22932 32391 99630 8082
    1 15 7 1 32 0 0 0 0
    2 2 1 0 0 0 0 0 0
    3 0 0 0 1 0 0 0 0

    Nate




    ________________________________

    From: David Winsemius
    Sent: Thu 5/24/2012 1:54 PM
    To: Nathan Svoboda
    Cc: r-help@r-project.org
    Subject: Re: [R] R Error: System is computationally singular



    On May 24, 2012, at 1:57 PM, Nathan Svoboda wrote:

    Greetings,

    I am trying to fit a zero-inflated Poisson model using zeroinfl()
    from the
    pscl library. I have 5 covariates (4 continuous, 1 categorical); the
    categorical variable has 7 levels. I have had success fitting
    models that
    contain only the continuous covariates; however, when I add the
    categorical
    variable to any of the models (or if I run it by itself) I get the
    following
    error:

    Error in solve.default(as.matrix(fit$hessian)) :

    system is computationally singular: reciprocal condition number =
    3.46934e-20

    The code I am using is:

    library(pscl)
    f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
    D_GRASS)
    ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

    There is no correlation between my covariates. Also, I tried
    reducing my
    categorical covariate to 3 levels and still receive the same error.
    Can
    anyone suggest why I may be getting this error when I add the
    categorical
    covariate?
    What does this show:

    with( FAWNS, table(LOCS, LCOVER) )

    --
    David Winsemius, MD
    West Hartford, CT
  • Nathan Svoboda at May 24, 2012 at 7:41 pm
    Hi David,

    My apologies, I am not sure if this makes a big difference in your assessment of the problem, but the results I just sent were only from a portion (1/15) of the data. The dataset is rather large and the computer I am currently using to set up the models is limited in its capabilities to analyze large datasets. When I run the code you provided on a larger portion of the data (1/2) this is the output I receive:

    LCOVER
    LOCS 1 2 3 4 5 6 7 9
    0 1692196 630659 550623 6140352 180896 255512 785929 63756
    1 141 30 48 279 9 14 36 1
    2 17 4 5 14 3 3 4 1
    3 0 0 0 3 0 0 1 0
    5 2 0 0 0 0 0 0 0

    Thanks again for your time and assistance,

    Nate

    Nathan Svoboda
    Graduate Research Assistant
    Mississippi State University


    ________________________________

    From: David Winsemius
    Sent: Thu 5/24/2012 1:54 PM
    To: Nathan Svoboda
    Cc: r-help@r-project.org
    Subject: Re: [R] R Error: System is computationally singular



    On May 24, 2012, at 1:57 PM, Nathan Svoboda wrote:

    Greetings,

    I am trying to fit a zero-inflated Poisson model using zeroinfl()
    from the
    pscl library. I have 5 covariates (4 continuous, 1 categorical); the
    categorical variable has 7 levels. I have had success fitting
    models that
    contain only the continuous covariates; however, when I add the
    categorical
    variable to any of the models (or if I run it by itself) I get the
    following
    error:

    Error in solve.default(as.matrix(fit$hessian)) :

    system is computationally singular: reciprocal condition number =
    3.46934e-20

    The code I am using is:

    library(pscl)
    f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
    D_GRASS)
    ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

    There is no correlation between my covariates. Also, I tried
    reducing my
    categorical covariate to 3 levels and still receive the same error.
    Can
    anyone suggest why I may be getting this error when I add the
    categorical
    covariate?
    What does this show:

    with( FAWNS, table(LOCS, LCOVER) )

    --
    David Winsemius, MD
    West Hartford, CT
  • Marc Schwartz at May 24, 2012 at 8:09 pm
    Nathan,

    This does help, as in the first cut you provided, there was no variability in LOCS for LCOVER >= 5 and you have very few values of LOCS > 0 (you still do, relative to the scale of the total).

    Have you tried using a zero inflated negative binomial model (dist = "negbin") rather than poisson? I am not sure that the assumption of a zero inflated poisson distribution is reasonable with your data. Also, at least in this cut of the data, you have no 4's in LOCS and no 8's in LCOVER (same as before).

    If my math is correct only 0.006% of your LOCS values are > 0. I am also not convinced that you have enough data to differentiate between 1 and >=1 of whatever it is you are counting in LOCS.

    If that is the case, you might want to consider using logistic regression with a dichotomous response variable of LOCS == 0 versus LOCS >= 1. You seem to be in the general realm of very rare events given the distribution of LOCS in your data.

    Regards,

    Marc Schwartz

    On May 24, 2012, at 2:41 PM, Nathan Svoboda wrote:

    Hi David,

    My apologies, I am not sure if this makes a big difference in your assessment of the problem, but the results I just sent were only from a portion (1/15) of the data. The dataset is rather large and the computer I am currently using to set up the models is limited in its capabilities to analyze large datasets. When I run the code you provided on a larger portion of the data (1/2) this is the output I receive:

    LCOVER
    LOCS 1 2 3 4 5 6 7 9
    0 1692196 630659 550623 6140352 180896 255512 785929 63756
    1 141 30 48 279 9 14 36 1
    2 17 4 5 14 3 3 4 1
    3 0 0 0 3 0 0 1 0
    5 2 0 0 0 0 0 0 0

    Thanks again for your time and assistance,

    Nate

    Nathan Svoboda
    Graduate Research Assistant
    Mississippi State University

    On May 24, 2012, at 1:57 PM, Nathan Svoboda wrote:

    Greetings,

    I am trying to fit a zero-inflated Poisson model using zeroinfl()
    from the
    pscl library. I have 5 covariates (4 continuous, 1 categorical); the
    categorical variable has 7 levels. I have had success fitting
    models that
    contain only the continuous covariates; however, when I add the
    categorical
    variable to any of the models (or if I run it by itself) I get the
    following
    error:

    Error in solve.default(as.matrix(fit$hessian)) :

    system is computationally singular: reciprocal condition number =
    3.46934e-20

    The code I am using is:

    library(pscl)
    f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
    D_GRASS)
    ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

    There is no correlation between my covariates. Also, I tried
    reducing my
    categorical covariate to 3 levels and still receive the same error.
    Can
    anyone suggest why I may be getting this error when I add the
    categorical
    covariate?
    What does this show:

    with( FAWNS, table(LOCS, LCOVER) )

    --
    David Winsemius, MD
    West Hartford, CT
  • Nathan Svoboda at May 25, 2012 at 1:34 am
    Thank you both,

    I will try using a zero inflated negative binomial as suggested. I had success with negative binomial on previous runs but only when I had fewer covariates and only ran a portion (10%) of the data.

    I may also try to reduce the number of covariates in the model (i.e., combine some of my landcover [LCOVER] classifications).

    I have considered using logistic regression and may end up trying that.

    I appreciate both of your input and will let you know (i.e., post) the results of these suggestions and what ends up working for the benefit of you and others.

    Thank you for your time and quick responses!!

    Nate


    Nathan Svoboda
    Graduate Research Assistant
    Carnivore Ecology Lab
    Mississippi State University


    ________________________________

    From: Marc Schwartz
    Sent: Thu 5/24/2012 3:09 PM
    To: Nathan Svoboda
    Cc: David Winsemius; r-help@r-project.org
    Subject: Re: [R] R Error: System is computationally singular



    Nathan,

    This does help, as in the first cut you provided, there was no variability in LOCS for LCOVER >= 5 and you have very few values of LOCS > 0 (you still do, relative to the scale of the total).

    Have you tried using a zero inflated negative binomial model (dist = "negbin") rather than poisson? I am not sure that the assumption of a zero inflated poisson distribution is reasonable with your data. Also, at least in this cut of the data, you have no 4's in LOCS and no 8's in LCOVER (same as before).

    If my math is correct only 0.006% of your LOCS values are > 0. I am also not convinced that you have enough data to differentiate between 1 and >=1 of whatever it is you are counting in LOCS.

    If that is the case, you might want to consider using logistic regression with a dichotomous response variable of LOCS == 0 versus LOCS >= 1. You seem to be in the general realm of very rare events given the distribution of LOCS in your data.

    Regards,

    Marc Schwartz

    On May 24, 2012, at 2:41 PM, Nathan Svoboda wrote:

    Hi David,

    My apologies, I am not sure if this makes a big difference in your assessment of the problem, but the results I just sent were only from a portion (1/15) of the data. The dataset is rather large and the computer I am currently using to set up the models is limited in its capabilities to analyze large datasets. When I run the code you provided on a larger portion of the data (1/2) this is the output I receive:

    LCOVER
    LOCS 1 2 3 4 5 6 7 9
    0 1692196 630659 550623 6140352 180896 255512 785929 63756
    1 141 30 48 279 9 14 36 1
    2 17 4 5 14 3 3 4 1
    3 0 0 0 3 0 0 1 0
    5 2 0 0 0 0 0 0 0

    Thanks again for your time and assistance,

    Nate

    Nathan Svoboda
    Graduate Research Assistant
    Mississippi State University

    On May 24, 2012, at 1:57 PM, Nathan Svoboda wrote:

    Greetings,

    I am trying to fit a zero-inflated Poisson model using zeroinfl()
    from the
    pscl library. I have 5 covariates (4 continuous, 1 categorical); the
    categorical variable has 7 levels. I have had success fitting
    models that
    contain only the continuous covariates; however, when I add the
    categorical
    variable to any of the models (or if I run it by itself) I get the
    following
    error:

    Error in solve.default(as.matrix(fit$hessian)) :

    system is computationally singular: reciprocal condition number =
    3.46934e-20

    The code I am using is:

    library(pscl)
    f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
    D_GRASS)
    ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

    There is no correlation between my covariates. Also, I tried
    reducing my
    categorical covariate to 3 levels and still receive the same error.
    Can
    anyone suggest why I may be getting this error when I add the
    categorical
    covariate?
    What does this show:

    with( FAWNS, table(LOCS, LCOVER) )

    --
    David Winsemius, MD
    West Hartford, CT
  • David Winsemius at May 25, 2012 at 12:15 am

    On May 24, 2012, at 3:41 PM, Nathan Svoboda wrote:

    Re: [R] R Error: System is computationally singular
    Hi David,

    My apologies, I am not sure if this makes a big difference in your
    assessment of the problem, but the results I just sent were only
    from a portion (1/15) of the data. The dataset is rather large and
    the computer I am currently using to set up the models is limited in
    its capabilities to analyze large datasets. When I run the code you
    provided on a larger portion of the data (1/2) this is the output I
    receive:

    LCOVER
    LOCS 1 2 3 4 5 6 7 9
    0 1692196 630659 550623 6140352 180896 255512 785929 63756
    1 141 30 48 279 9 14 36 1
    2 17 4 5 14 3 3 4 1
    3 0 0 0 3 0 0 1 0
    5 2 0 0 0 0 0 0 0
    I do not see linear dependence (aka computational singularity) in that
    data, but if there are no LOCS values of 4, an missing levels has been
    reported as a show-stopper with zinf models with pscl in the past.
    There could also easily emerge linear dependence if you tabulated the
    entire data set. If level 4 had 3 at level 4 of LCOVER or 1 at level 7
    then there would be linear dependence.

    Marc Schwartz, a smarter guy than I, has already suggested to you
    that your Poisson error structure might not be a good description of
    the data.

    Thanks again for your time and assistance,

    Nate

    Nathan Svoboda
    Graduate Research Assistant
    Mississippi State University


    From: David Winsemius [mailto:dwinsemius at comcast.net]
    Sent: Thu 5/24/2012 1:54 PM
    To: Nathan Svoboda
    Cc: r-help at r-project.org
    Subject: Re: [R] R Error: System is computationally singular

    On May 24, 2012, at 1:57 PM, Nathan Svoboda wrote:

    Greetings,

    I am trying to fit a zero-inflated Poisson model using zeroinfl()
    from the
    pscl library. I have 5 covariates (4 continuous, 1 categorical); the
    categorical variable has 7 levels. I have had success fitting
    models that
    contain only the continuous covariates; however, when I add the
    categorical
    variable to any of the models (or if I run it by itself) I get the
    following
    error:

    Error in solve.default(as.matrix(fit$hessian)) :

    system is computationally singular: reciprocal condition number =
    3.46934e-20

    The code I am using is:

    library(pscl)
    f1 <- formula(LOCS ~ as.factor(LCOVER) + D_ROADS + D_WATER + D_EDGE +
    D_GRASS)
    ZIP1 <- zeroinfl(f1, dist="poisson", link = "logit", data = FAWNS)

    There is no correlation between my covariates. Also, I tried
    reducing my
    categorical covariate to 3 levels and still receive the same error.
    Can
    anyone suggest why I may be getting this error when I add the
    categorical
    covariate?
    What does this show:

    with( FAWNS, table(LOCS, LCOVER) )

    --
    David Winsemius, MD
    West Hartford, CT
    David Winsemius, MD
    West Hartford, CT
  • Nathan Svoboda at May 24, 2012 at 7:17 pm
    Thank you for your quick reply,

    When I run the code you provide I get this output:

    LCOVER
    LOCS 1 2 3 4 5 6 7 9
    0 214507 79939 69803 778359 22932 32391 99630 8082
    1 15 7 1 32 0 0 0 0
    2 2 1 0 0 0 0 0 0
    3 0 0 0 1 0 0 0 0

    Nate



    --
    View this message in context: http://r.789695.n4.nabble.com/R-Error-System-is-computationally-singular-tp4631242p4631251.html
    Sent from the R help mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post