[R-sig-ME] Unable to standardize glmmADMB global model

Aoibheann Gaughran gaughra at tcd.ie
Thu Aug 18 15:11:43 CEST 2016


> names(std_data) [1] "field_count"     "month_fix"       "num_fields"      "field_id"        "animal"          "soc_grp"         "habitat"
 [8] "habitat2"        "monyear"         "mon"             "season_wt"
      "season"          "month"           "year"
[15] "sex"             "age"             "ageclass"        "soil"
      "slope"           "elevation"       "aspect"
[22] "NSEW"            "origarea"        "newarea"         "HRNewArea"
      "HabNewArea"      "PropAvlHab"      "origperim"
[29] "newperim"        "propHRfield"     "percentHRfield"
"PropHabfield"    "percentHabfield" "field_use"       "slopescale"
[36] "aspectscale"     "z.month_fix"     "z.num_fields"    "z.slope"
      "z.origarea"      "z.PropAvlHab"


On 18 August 2016 at 14:07, Ben Bolker <bbolker at gmail.com> wrote:

>
>   what's the results of names(std_data) ?
>
> On 16-08-18 09:05 AM, Aoibheann Gaughran wrote:
> > Hi Ben,
> >
> > I've manually scaled and centered the continuous variables, and just
> > scaled the offset terms.  However, I now get the following error message
> > when I attempt to run the model, which appears to related to a
> > subsetting issue?
> >
> > Error in `[.data.frame`(cor_dat, start_pos + (1:x$npar), start_pos + 4
> +  :
> > undefined columns selected
> >
> > The revised global model is specified as follows:
> >
> > stdmod12d <- glmmadmb(field_count ~ habitat #categorical
> >                      + season_wt #cat
> >                      + sex #cat
> >                      + ageclass #cat
> >                      + z.slope #continuous, scaled and centred
> >                      + NSEW #cat
> >                      + z.month_fix #continuous, scaled and centred
> >                      + z.num_fields #continuous, scaled and centred
> >                      + habitat:ageclass
> >                      + habitat:sex
> >                      + offset(log(z.origarea)) #scaled
> >                      + offset(log(z.PropAvlHab)) #scaled
> >                      +(1|animal) #repeated obs from same individual
> >                      +(1|field_id) #repeated obs in same field
> >                      ,
> >                      family="nbinom",
> >                      zeroInflation=TRUE,
> >                      admb.opts=admbControl(shess=FALSE,noinit=FALSE),
> >                      debug=TRUE,
> >                      data = std_data)
> >
> > On 16 August 2016 at 12:55, Ben Bolker <bbolker at gmail.com
> > <mailto:bbolker at gmail.com>> wrote:
> >
> >     You can *scale* the offsets if you like, i.e. change them by a
> >     multiplicative factor (thus changing the effective area unit for
> which
> >     you were modeling counts), but *centering* them doesn't make sense --
> >     as you've noticed.
> >
> >     On Tue, Aug 16, 2016 at 7:40 AM, Aoibheann Gaughran <gaughra at tcd.ie
> >     <mailto:gaughra at tcd.ie>> wrote:
> >     > Hi Ben,
> >     >
> >     > Im proceeding by standardizing by hand.  However, I need to
> >     include offsets
> >     > in my model for origarea and PropAvlHab i.e.
> >     offset(log(z.origarea)) but
> >     > logging the standardized varible produced NaNs due to the presence
> of
> >     > negative numbers, ditto with z.PropAvlHab. Is there a way around
> >     this? Do I
> >     > need to also standardize the offset terms or can I leave them in
> their
> >     > unstandardized form?
> >     >
> >     > Many thanks,
> >     >
> >     > Aoibheann
> >     >
> >     > On 15 August 2016 at 15:47, Ben Bolker <bbolker at gmail.com
> >     <mailto:bbolker at gmail.com>> wrote:
> >     >>
> >     >> Hmm.  Surprising/hard to diagnose.
> >     >>
> >     >> 'standardize' doesn't do anything very fancy - it standardizes the
> >     >> input variables as described by ?arm::standardize and *refits* the
> >     >> model (I've always been a little disappointed that it doesn't
> >     >> standardize by figuring out how to transform the *parameters*,
> which
> >     >> is straightforward in principle although it can be tricky to
> figure
> >     >> out how to deal with input variables that lead to multiple
> predictor
> >     >> variables, e.g. polynomials).  I'd be curious to know what's
> >     going on,
> >     >> but in your place I would
> >     >>
> >     >> (1) try standardizing by hand, e.g.
> >     >>
> >     >> std_data <- transform(data,
> >     >>       z.season.wt = scale(season.wt),
> >     >>      ...)
> >     >>
> >     >> and refit yourself.
> >     >>
> >     >> (2) see if it happens to work with glmmTMB (a simple example
> does).
> >     >>
> >     >>   Ben Bolker
> >     >>
> >     >>
> >     >>
> >     >>
> >     >> On Mon, Aug 15, 2016 at 10:37 AM, Aoibheann Gaughran
> >     <gaughra at tcd.ie <mailto:gaughra at tcd.ie>>
> >     >> wrote:
> >     >> > Thanks Ben, I ran the code and got the following error and
> >     warnings:-
> >     >> >
> >     >> > Error in glmmadmb(formula = field_count ~ habitat + season_wt +
> >     c.sex +
> >     >> > :
> >     >> >   rank of X = 16 < ncol(X) = 24
> >     >> > In addition: Warning messages:
> >     >> > 1: In log(z.PropAvlHab) : NaNs produced
> >     >> > 2: In glmmadmb(formula = field_count ~ habitat + season_wt +
> >     c.sex +  :
> >     >> >   NAs removed in constructing fixed-effect model frame: you
> should
> >     >> > probably
> >     >> > remove them manually, e.g. with na.omit()
> >     >> >
> >     >> >
> >     >> > The original PropAvlHab summary is as follows:-
> >     >> >
> >     >> >> summary(dframe1$PropAvlHab)
> >     >> >      Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
> >     >> > 0.0000123 0.1123000 0.4041000 0.4078000 0.6818000 1.0000000
> >     >> >
> >     >> > Aoibheann
> >     >> >
> >     >> >
> >     >> >
> >     >> > On 15 August 2016 at 15:12, Ben Bolker <bbolker at gmail.com
> >     <mailto:bbolker at gmail.com>> wrote:
> >     >> >>
> >     >> >> 'standardize' is a function from the arm package.
> >     >> >>
> >     >> >> I've just hacked glmmADMB a little bit so this should work:
> >     >> >>
> >     >> >> library(devtools)
> >     >> >> install_github("bbolker/glmmADMB")  ## install latest version
> >     >> >> library(arm)
> >     >> >> arm:::standardize.default(fitted_model$call)
> >     >> >>
> >     >> >>
> >     >> >>
> >     >> >> On Mon, Aug 15, 2016 at 5:06 AM, Aoibheann Gaughran
> >     <gaughra at tcd.ie <mailto:gaughra at tcd.ie>>
> >     >> >> wrote:
> >     >> >> > Hello Mixed-Modellers,
> >     >> >> >
> >     >> >> > I have getting the following error message when trying to
> >     standardize
> >     >> >> > my
> >     >> >> > global glmmadmb model for dredging:
> >     >> >> >
> >     >> >> > Error in (function (classes, fdef, mtable)  : unable to find
> an
> >     >> >> > inherited
> >     >> >> > method for function ‘standardize’ for signature ‘"glmmadmb"’
> >     >> >> >
> >     >> >> > Is it not possible to standardise a glmmadmb model or is the
> >     problem
> >     >> >> > with
> >     >> >> > the structure of the model itself?
> >     >> >> >
> >     >> >> > globalmod    <- glmmadmb(field_count ~ habitat
> >     >> >> > #categorical - 7 levels
> >     >> >> >                      + season_wt
> >     >> >> >                                          #categorial - 3
> levels
> >     >> >> >                      + sex
> >     >> >> >                                               #categorial -
> >     2 levels
> >     >> >> >                      + ageclass
> >     >> >> >                                            #categorial - 3
> >     levels
> >     >> >> >                      + slope
> >     >> >> >                                              #continuous,
> >     not scaled
> >     >> >> > nor
> >     >> >> > centred
> >     >> >> >                      + NSEW
> >     >> >> >                                           #catagorical - 4
> >     levels
> >     >> >> >                      + month_fix
> >     >> >> >                                           #continuous, not
> >     scaled nor
> >     >> >> > centred,
> >     >> >> >                      + num_fields
> >     >> >> >                   #continuous, not scaled nor centred
> >     >> >> >                      + habitat:ageclass
> >     >> >> >                      + habitat:sex
> >     >> >> >                      + offset(log(origarea))
> >     >> >> >                      + offset(log(PropAvlHab))
> >     >> >> >                      +(1|individual_id)
> >     >> >> >                                            #repeated obs
> >     from same
> >     >> >> > individual
> >     >> >> >                      +(1|field_id)
> >     >> >> >                                               #repeated obs
> >     in same
> >     >> >> > field,
> >     >> >> >                      family="nbinom",
> >     >> >> >                      zeroInflation=TRUE,
> >     >> >> >
> >     admb.opts=admbControl(shess=FALSE,noinit=FALSE),
> >     >> >> >                      debug=TRUE,
> >     >> >> >                      data = dframe1)
> >     >> >> >
> >     >> >> > no of observations =9220
> >     >> >> >
> >     >> >> > Many thanks,
> >     >> >> >
> >     >> >> > --
> >     >> >> > Aoibheann Gaughran
> >     >> >> >
> >     >> >> > Behavioural and Evolutionary Ecology Research Group
> >     >> >> > Zoology Building
> >     >> >> > School of Natural Sciences
> >     >> >> > Trinity College Dublin
> >     >> >> > Dublin 2
> >     >> >> > Ireland
> >     >> >> > Phone: +353 (86) 3812615
> >     >> >> >
> >     >> >> >         [[alternative HTML version deleted]]
> >     >> >> >
> >     >> >> > _______________________________________________
> >     >> >> > R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org> mailing list
> >     >> >> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >> >
> >     >> >
> >     >> >
> >     >> >
> >     >> > --
> >     >> > Aoibheann Gaughran
> >     >> >
> >     >> > Behavioural and Evolutionary Ecology Research Group
> >     >> > Zoology Building
> >     >> > School of Natural Sciences
> >     >> > Trinity College Dublin
> >     >> > Dublin 2
> >     >> > Ireland
> >     >> > Phone: +353 (86) 3812615 <tel:%2B353%20%2886%29%203812615>
> >     >
> >     >
> >     >
> >     >
> >     > --
> >     > Aoibheann Gaughran
> >     >
> >     > Behavioural and Evolutionary Ecology Research Group
> >     > Zoology Building
> >     > School of Natural Sciences
> >     > Trinity College Dublin
> >     > Dublin 2
> >     > Ireland
> >     > Phone: +353 (86) 3812615 <tel:%2B353%20%2886%29%203812615>
> >
> >
> >
> >
> > --
> > Aoibheann Gaughran
> >
> > Behavioural and Evolutionary Ecology Research Group
> > Zoology Building
> > School of Natural Sciences
> > Trinity College Dublin
> > Dublin 2
> > Ireland
> > Phone: +353 (86) 3812615
>



-- 
Aoibheann Gaughran

Behavioural and Evolutionary Ecology Research Group
Zoology Building
School of Natural Sciences
Trinity College Dublin
Dublin 2
Ireland
Phone: +353 (86) 3812615

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list