using predict function with model including offset for transect length

227 views
Skip to first unread message

Alex Anderson

unread,
Nov 12, 2013, 5:21:01 AM11/12/13
to unma...@googlegroups.com
Hi All,
I am trying to use pcount to model bird abundances using some
variable-width transect counts in forest. To deal with some low
detectability species I have aggregated (summed) counts from points
clustered within sites (typically transects separated by 200m in
clusters of 3 to 6). As different total numbers of points per cluster
were sampled on each visits, I have tried to add an area offset
consisting of the log of the sum of the transect distances walked per
visit. My model looks like this:


pcount(formula = ~wet + season + temp_anomaly + month +
offset(log(distance)) ~ MATemp + MATemp2 + aspect + annual_pptn12 +
time_step3 + MATemp.time_step3 + MATemp2.time_step3, data = spp.umf,
K = 200, mixture = "NB", starts = c(1, -1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), engine = "C")

Abundance:
Estimate SE z P(>|z|)
(Intercept) 4.2043 0.2637 15.941 3.31e-57
MATemp 0.4634 0.2337 1.983 4.74e-02
MATemp2 -0.3724 0.2316 -1.608 1.08e-01
aspect 0.1153 0.0661 1.744 8.11e-02
annual_pptn12 -0.0947 0.1082 -0.876 3.81e-01
time_step3 0.1359 0.1628 0.835 4.04e-01
MATemp.time_step3 0.0224 0.1492 0.150 8.80e-01
MATemp2.time_step3 0.0570 0.1435 0.397 6.91e-01

Detection:
Estimate SE z P(>|z|)
(Intercept) -16.5465 0.16947 -97.64 0.00e+00
wet -0.0931 0.03555 -2.62 8.85e-03
season 0.2179 0.07809 2.79 5.27e-03
temp_anomaly 0.5371 0.04552 11.80 3.95e-32
month 0.0823 0.00823 10.00 1.49e-23

Dispersion:
Estimate SE z P(>|z|)
1.4 0.241 5.81 6.34e-09

AIC: 2738.876

When I try to use the predict function however, even if I have obscovs
in my new data object that include the distance offset, the predictions
do not appear to scale according to the offset, so that my maximum
predicted N values are very high... I thought that using offset resulted
in estimates that were proportional to the sampling units, ie divided by
the offset in each case... am I missing something obvious?

code I am using is:

E.psi = predictSE.zip(fm26, newdata =newData2, se.fit = TRUE, parm.type
= "lambda",
type = "response", print.matrix = FALSE)


and example output of predict looks like this

Predicted SE lower
1 6.963488 4.395072 -1.65085342
2 7.491457 4.565585 -1.45708879
3 8.051630 4.735467 -1.22988442
4 8.645287 4.904113 -0.96677478
5 9.273701 5.070900 -0.66526410
6 9.938133 5.235191 -0.32284166
7 10.639827 5.396340 0.06300115
8 11.380005 5.553700 0.49475194
9 12.159854 5.706632 0.97485634
10 12.980528 5.854507 1.50569517
11 13.843134 5.996722 2.08955940
12 14.748728 6.132706 2.72862310
13 15.698304 6.261934 3.42491424
14 16.692793 6.383934 4.18028334
15 17.733046 6.498304 4.99637007
16 18.819832 6.604727 5.87456779
17 19.953827 6.702980 6.81598621
18 21.135608 6.792957 7.82141246
19 22.365641 6.874679 8.89127069
20 23.644276 6.948314 10.02558098
21 24.971737 7.014193 11.22391801
22 26.348115 7.072829 12.48537061
23 27.773360 7.124927 13.80850339
24 29.247272 7.171403 15.19132230
25 30.769495 7.213393 16.63124611
26 32.339511 7.252257 18.12508673
27 33.956631 7.289586 19.66904148
28 35.619991 7.327189 21.25870105
29 37.328546 7.367076 22.88907690
30 39.081068 7.411437 24.55465191
31 40.876136 7.462591 26.24945713
32 42.712138 7.522940 27.96717611
33 44.587268 7.594894 29.70127596
34 46.499521 7.680796 31.44516130
35 48.446695 7.782832 33.19234393
36 50.426393 7.902947 34.93661789
37 52.436021 8.042752 36.67222738
38 54.472789 8.203456 38.39401432
39 56.533720 8.385809 40.09753386
40 58.615650 8.590061 41.77912944
41 60.715234 8.815954 43.43596355
42 62.828953 9.062729 45.06600541
43 64.953124 9.329155 46.66798116
44 67.083905 9.613577 48.24129497
45 69.217306 9.913967 49.78593090
46 71.349202 10.227988 51.30234483
47 73.475341 10.553054 52.79135453
48 75.591362 10.886392 54.25403363
49 77.692805 11.225098 55.69161339
50 79.775125 11.566189 57.10539410
51 81.833713 11.906656 58.49666656
52 83.863906 12.243502 59.86664291
53 85.861009 12.573782 61.21639578
54 87.820307 12.894644 62.54680411
55 89.737090 13.203360 63.85850416
56 91.606667 13.497359 65.15184422
57 93.424386 13.774257 66.42684165
58 95.185652 14.031893 67.68314120
59 96.885947 14.268354 68.91997359
60 98.520852 14.482010 70.13611358
61 100.086061 14.671543 71.32983707
62 101.577403 14.835983 72.49887671

?
Thanks in advance.
Alex

##########

my UMF object looks like this

Tabulation of y observations:
0 1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16 17 18 22 23
214 52 36 33 22 23 22 15 14 11 10 11 4 6
4 1 5 3 2 1 2
24 25 31 47 <NA>
1 1 1 1 1249

Site-level covariates:
new_site2 MATemp.V1 accu04.V1
annual_pptn12.V1 latdd.V1
AU10A_1: 1 Min. :-2.2996325 Min. :-3.0394559 Min.
:-0.990535 Min. :-1.5479263
AU10A_2: 1 1st Qu.:-0.8104350 1st Qu.:-0.5855316 1st
Qu.:-0.561010 1st Qu.:-0.7580974
AU10B_2: 1 Median :-0.0517615 Median : 0.2556761 Median
:-0.300353 Median :-0.1742186
AU1A_1 : 1 Mean : 0.0000000 Mean : 0.0000000 Mean :
0.000000 Mean : 0.0000000
AU1A_2 : 1 3rd Qu.: 0.7952043 3rd Qu.: 0.7160325 3rd Qu.:
0.367850 3rd Qu.: 0.8942684
AU2A_1 : 1 Max. : 1.9926697 Max. : 1.7626554 Max. :
4.065755 Max. : 1.6428528
(Other):103
slope.V1 aspect.V1 dem_250.V1 time_step3
MATemp2.V1
Min. :-1.107915 Min. :-1.8411264 Min. :-1.7209589 Min.
:1.000 Min. :0.000540
1st Qu.:-0.749198 1st Qu.:-0.8908789 1st Qu.:-0.7197289 1st
Qu.:1.000 1st Qu.:0.095310
Median :-0.268954 Median : 0.1062330 Median : 0.0836678 Median
:1.000 Median :0.656805
Mean : 0.000000 Mean : 0.0000000 Mean : 0.0000000 Mean
:1.422 Mean :0.990826
3rd Qu.: 0.410285 3rd Qu.: 0.6336888 3rd Qu.: 0.6469571 3rd
Qu.:2.000 3rd Qu.:1.561748
Max. : 4.086832 Max. : 2.3896341 Max. : 2.2534097 Max.
:2.000 Max. :5.288309

MATemp.time_step3.V1 MATemp2.time_step3.V1 lat.dem_250.V1
Min. :-4.599265 Min. : 0.000540 Min. :-2.2993064
1st Qu.:-0.880879 1st Qu.: 0.095310 1st Qu.:-0.4928145
Median :-0.061627 Median : 0.768639 Median : 0.0253640
Mean : 0.047972 Mean : 1.479135 Mean :-0.0009588
3rd Qu.: 0.993895 3rd Qu.: 2.089684 3rd Qu.: 0.5053981
Max. : 3.985339 Max. :10.576619 Max. : 1.8728838


Observation-level covariates:
wet.V1 wind temp_anomaly.V1 month
start season
Min. :-1.5932 Min. :0.000 Min. :-4.3765 Min. : 1.000
Min. :5.737 Min. :1.00
1st Qu.:-0.6065 1st Qu.:0.000 1st Qu.:-0.6039 1st Qu.: 3.000
1st Qu.:6.665 1st Qu.:1.00
Median :-0.1132 Median :0.500 Median : 0.1797 Median : 6.000
Median :6.995 Median :2.00
Mean : 0.0000 Mean :1.067 Mean : 0.0000 Mean : 6.238
Mean :7.004 Mean :1.58
3rd Qu.: 0.8735 3rd Qu.:1.775 3rd Qu.: 0.6695 3rd Qu.:10.000
3rd Qu.:7.317 3rd Qu.:2.00
Max. : 2.3536 Max. :5.000 Max. : 2.3281 Max. :12.000
Max. :8.967 Max. :2.00
NA's :1249 NA's :1249 NA's :1249 NA's :1249
NA's :1249 NA's :1249
distance time_step3
Min. : 128.0 Min. :1.000
1st Qu.: 300.0 1st Qu.:1.000
Median : 484.0 Median :1.000
Mean : 559.5 Mean :1.448
3rd Qu.: 766.5 3rd Qu.:2.000
Max. :2613.0 Max. :2.000
NA's :1249 NA's :1249


Marc J. Mazerolle

unread,
Nov 12, 2013, 9:28:41 AM11/12/13
to unma...@googlegroups.com
Hi Alex,

If you want to scale abundances with the offset, the offset should be on
abundance, not detection.

Best,

Marc
--
____________________________________
Marc J. Mazerolle
Centre d'étude de la forêt
Université du Québec en Abitibi-Témiscamingue
445 boulevard de l'Université
Rouyn-Noranda, Québec J9X 5E4, Canada
Tel: (819) 762-0971 ext. 2458
Email: marc.ma...@uqat.ca


-------- Message initial --------
De: Alex Anderson <alejandro....@gmail.com>
À: unma...@googlegroups.com
Sujet: [unmarked] using predict function with model including offset for
transect length
Date: Tue, 12 Nov 2013 17:21:01 +0700
--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Alex Anderson

unread,
Nov 12, 2013, 10:16:51 AM11/12/13
to unma...@googlegroups.com
Hi Marc,
Thanks so much for your quick reply. Apologies, I have tried this, but
I must be still missing something, or perhaps did not explain my
situation well. Because the total number of transects, and hence
distane, walked within each site varies between visits, I could not see
how create a transect length covariate at the site level. Adding the my
observation level distance offset at the site level yields:

> (fm29 <- pcount(~wet+season+temp_anomaly+month ~
MATemp+MATemp2+aspect+annual_pptn12+ time_step3 +MATemp.time_step3 +
MATemp2.time_step3 + offset(log(distance)), spp.umf, starts =
c(1,-1,0,0,0,0,0,0,0,0,0,0,0,0), K = 200,mixture = "NB", engine = "C"))

Error in offset(log(distance)) : object 'distance' not found

Thanks again
A

Marc J. Mazerolle

unread,
Nov 12, 2013, 10:26:13 AM11/12/13
to unma...@googlegroups.com
Alex,

Be sure that the newdata2 data frame includes values of distance in
addition to the variables on abundance in your model.

Marc
--
____________________________________
Marc J. Mazerolle
Centre d'étude de la forêt
Université du Québec en Abitibi-Témiscamingue
445 boulevard de l'Université
Rouyn-Noranda, Québec J9X 5E4, Canada
Tel: (819) 762-0971 ext. 2458
Email: marc.ma...@uqat.ca


-------- Message initial --------
De: Alex Anderson <alejandro....@gmail.com>
À: unma...@googlegroups.com
Sujet: Re: [unmarked] using predict function with model including offset
for transect length
Date: Tue, 12 Nov 2013 22:16:51 +0700

Alex Anderson

unread,
Nov 12, 2013, 10:48:08 AM11/12/13
to unma...@googlegroups.com
Hi again,
Thanks for your continued attention to my questions. My new data object
look like this:

MATemp annual_pptn12 latdd aspect dem_250 slope
start wet wind
1 -2.299632 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17
-7.300958e-17 NA -1.593214 1.06712
2 -2.256276 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17
-7.300958e-17 NA -1.553347 1.06712
3 -2.212919 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17
-7.300958e-17 NA -1.513481 1.06712
4 -2.169563 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17
-7.300958e-17 NA -1.473614 1.06712
5 -2.126206 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17
-7.300958e-17 NA -1.433748 1.06712
6 -2.082850 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17
-7.300958e-17 NA -1.393881 1.06712
season distance temp_anomaly
1 1.579798 559.4578 4.078133e-18
2 1.579798 559.4578 4.078133e-18
3 1.579798 559.4578 4.078133e-18
4 1.579798 559.4578 4.078133e-18
5 1.579798 559.4578 4.078133e-18
6 1.579798 559.4578 4.078133e-18



The "distance" covariate is currently set at the mean value, but I have
also tried it set at 1 and 150, to no avail. The abundance estimates
remain unmoved.
Cheers
A

Alex Anderson

unread,
Nov 12, 2013, 10:48:38 AM11/12/13
to unma...@googlegroups.com
Hi again Marc,
Thanks for your continued attention to my questions.  My newdata object look like this:


     MATemp annual_pptn12        latdd        aspect       dem_250         slope start       wet    wind
1 -2.299632 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17 -7.300958e-17    NA -1.593214 1.06712
2 -2.256276 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17 -7.300958e-17    NA -1.553347 1.06712
3 -2.212919 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17 -7.300958e-17    NA -1.513481 1.06712
4 -2.169563 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17 -7.300958e-17    NA -1.473614 1.06712
5 -2.126206 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17 -7.300958e-17    NA -1.433748 1.06712
6 -2.082850 -1.882235e-16 1.478597e-15 -3.037358e-17 -1.413342e-17 -7.300958e-17    NA -1.393881 1.06712
    season distance temp_anomaly
1 1.579798 559.4578 4.078133e-18
2 1.579798 559.4578 4.078133e-18
3 1.579798 559.4578 4.078133e-18
4 1.579798 559.4578 4.078133e-18
5 1.579798 559.4578 4.078133e-18
6 1.579798 559.4578 4.078133e-18



The "distance" covariate (in bold) is currently set at the mean value, but I have also tried it set at 1 and 150, to no avail.  The abundance estimates remain unmoved.
Cheers
A


On 12/11/13 10:26 PM, Marc J. Mazerolle wrote:

Marc J. Mazerolle

unread,
Nov 12, 2013, 3:44:36 PM11/12/13
to unma...@googlegroups.com
Alex,

I found the problem and will make the necessary changes to
predictSE.zip. I'll submit a new version of AICcmodavg on CRAN later
this week.

Best,

Marc
--
____________________________________
Marc J. Mazerolle
Centre d'étude de la forêt
Université du Québec en Abitibi-Témiscamingue
445 boulevard de l'Université
Rouyn-Noranda, Québec J9X 5E4, Canada
Tel: (819) 762-0971 ext. 2458
Email: marc.ma...@uqat.ca


-------- Message initial --------
De: Alex Anderson <alejandro....@gmail.com>
À: unma...@googlegroups.com
Sujet: Re: [unmarked] using predict function with model including offset
for transect length
Date: Tue, 12 Nov 2013 22:48:08 +0700

Alex Anderson

unread,
Nov 13, 2013, 4:06:11 AM11/13/13
to unma...@googlegroups.com
Hi Marc,
Thanks for taking the time to check that out. I fear I may still be
misunderstanding something though, as I cannot see any influence on
estimated N when changing my "newdata" distance offsett values, even
when using the standard predict() function from unmarked (with an NB model).
Cheers
A

On 13/11/13 3:44 AM, Marc J. Mazerolle wrote:
> Alex,
>

alejandro....@gmail.com

unread,
Nov 22, 2013, 12:41:55 AM11/22/13
to unma...@googlegroups.com
Hi Marc,
Thanks for posting that update (I assume the most recent one included some changes?) however, I am still stumped as to how this offset function is supposed to work.  When I repeat the attempt using an updated AICcmodavg, I still see no influence of the offset in scaling my estimated abundances.. any tips? am I missing something?
Cheers
A

Marc.Ma...@uqat.ca

unread,
Nov 22, 2013, 9:09:43 AM11/22/13
to unma...@googlegroups.com
Hi Alejandro,

Both predict( ) in unmarked and predictSE.zip( ) in package AICcmodavg (>= version 1.35) produce the same prediction when using an offset. To illustrate what an offset does, you might want to experiment a bit with a Poisson distribution (instead of a ZIP).

When you are modelling an abundance as a rate (abundance per transect length for example), you are actually doing the following:

log(mu/transect.length) = linear predictor

log(mu) - log(transect.length) = linear predictor

log(mu) = linear predictor + log(transect.length)

Note that the linear predictor is the combination of beta estimates and explanatory variables forming the predictive equation.

Thus, if you want the predicted value of abundance for a given transect length, you have to exponentiate:

mu = exp(linear predictor + log(transect.length))

This is what happens with predict( ) and predictSE.zip( ) for a Poisson. For the zero-inflated Poisson, you must compute the linear predictor for the Poisson as above, but the final step involves:

mu = exp(linear predictor + log(transect.length)) * (1 - (exp(psi.pred)/(1 + exp(psi.pred))))

This is because the zero-inflated Poisson includes an additional parameter psi and its beta estimate is on a logit scale.

I suggest you work one of your examples using a simple model with only a single variable on abundance.

Hope it helps,

Marc M

--
____________________________________
Marc J. Mazerolle
Centre d'étude de la forêt
Université du Québec en Abitibi-Témiscamingue
445 boulevard de l'Université
Rouyn-Noranda, Québec J9X 5E4, Canada
Tel: (819) 762-0971 ext. 2458
Email: marc.ma...@uqat.ca

De : unma...@googlegroups.com [unma...@googlegroups.com] de la part de alejandro....@gmail.com [alejandro....@gmail.com]
Date d'envoi : vendredi 22 novembre 2013 00:41
À : unma...@googlegroups.com
Objet : Re: [unmarked] using predict function with model including offset for transect length

Alex Anderson

unread,
Nov 22, 2013, 1:19:41 PM11/22/13
to unma...@googlegroups.com
Hi Marc,
Thanks very much for your detailed reply, I was not aware of this added layer of complexity when using an offset.  I will have a go at you simple example and then try to scale up to my multiple covariate models as you suggest.
Cheers
A

Alex Anderson

unread,
Dec 4, 2013, 12:33:38 AM12/4/13
to unma...@googlegroups.com
Hi Marc,
Thanks again for your help.  So I am having a go exponentiating my predictions from pcount() based on the code in your reply.  I think I am still doing something incorrectly, as the estimates do not seem to make any sense? the code I am using is below.  I think my problem might lie in my interpretation of linear predictor.  You mentioned that this is "the combination of beta estimates and explanatory variables forming the predictive equation"... Is this the same as my predicted value from my model using predictSE.zip()?  If not, some tips on how to derive that would be much appreciated! My apologies for this basic question, (modelling is not my strong point... rather field surveys of forest birds!).
Cheers
A

> (fm1 <- pcount(~1 ~ MATemp2.time_step3,mixture = "ZIP",spp.umf,K = 60))


Call:
pcount(formula = ~1 ~ MATemp2.time_step3, data = spp.umf, K = 60,
    mixture = "ZIP")


Abundance:
                   Estimate     SE    z P(>|z|)
(Intercept)          3.2860 0.0397 82.8   0.000
MATemp2.time_step3  -0.0222 0.0202 -1.1   0.271


Detection:
 Estimate     SE     z   P(>|z|)
    -1.18 0.0407 -28.9 2.48e-183

Zero-inflation:

 Estimate   SE     z  P(>|z|)
    -1.07 0.22 -4.85 1.23e-06

AIC: 4954.28
> E.psi = backTransform(fm1, type="psi")
> tpsi = E.psi@parentLinComb@estimate
> E.abund = predictSE.zip(fm10, newdata =newData2, se.fit = TRUE, parm.type = "lambda",
+                       type = "response", print.matrix = FALSE)
> head(E.abund)$fit

          1           2           3           4           5           6           7           8
 15.9320166  17.7701098  19.7587658  21.9018026  24.2019439  26.6606653  29.2780440  32.0526159

> E.abund = as.data.frame(E.abund)
> E.abund$upper = E.abund$fit + (1.96 * E.abund$se.fit )
> E.abund$lower = E.abund$fit - (1.96 * E.abund$se.fit )
> E.abund    = cbind(E.abund, newData2)
>
> # predicting the abundance with an offset for survey area
> E.abund$mu = exp(E.abund$fit + log(300*max_dist)) * (1 - (exp(tpsi)/(1 + exp(tpsi))))
> head(E.abund$mu)

  [1] 1.483213e+11 9.321318e+11 6.809883e+12 5.805621e+13 5.791451e+14 6.770122e+15 9.274909e+16
  [8] 1.486931e+18 2.780851e+19 6.037115e+20 1.511070e+22 4.322417e+23 1.397851e+25 5.045502e+26
 [15]
--
Dr. Alexander Anderson
Norwegian University of Life Sciences
Department of Ecology and Natural Resource Management

email: alexander...@my.jcu.edu.au
research website: www.rainforestbird.wordpress.com
photos: www.flickr.com/complicando
M: +61 (0) 0424464607
Message has been deleted

Alex Anderson

unread,
Dec 4, 2013, 3:27:29 AM12/4/13
to unma...@googlegroups.com
Hi All,
apologies again, last post was full of typos, and the code above was from a previous test that did not include the offset. Please see below.  I think I have made an obvious mistake:  my offset is on the detection, not the abundance process.  But when I try to predict with a model using an offset on abundance, I get an error because the transects varied between visits, not between sites.

>(fm1 <- pcount(~1 ~ MATemp2.time_step3 + offset(log(2*(distance*max_dist))),mixture = "ZIP",spp.umf,K = 60))
Error in offset(log(2 * (distance * max_dist))) :
  object 'distance' not found


Any ideas?
Cheers
A

correct code:

> (fm1 <- pcount(~1 +offset(log(2*(distance*max_dist))) ~ MATemp2.time_step3, mixture = "ZIP",spp.umf,K = 60))

Call:
pcount(formula = ~1 + offset(log(2 * (distance * max_dist))) ~
    MATemp2.time_step3, data = spp.umf, K = 60, mixture = "ZIP")

Abundance:
                   Estimate     SE      z P(>|z|)
(Intercept)          3.4466 0.0396 86.967   0.000
MATemp2.time_step3  -0.0113 0.0196 -0.577   0.564


Detection:
 Estimate     SE    z P(>|z|)
    -12.8 0.0414 -309       0


Zero-inflation:
 Estimate    SE     z  P(>|z|)
    -1.22 0.244 -5.01 5.32e-07

AIC: 4269.433
> E.psi = backTransform(fm1, type="psi")
> tpsi = E.psi@parentLinComb@estimate
> E.abund = predictSE.zip(fm1, newdata =newData2, se.fit = TRUE, parm.type = "lambda",

+                       type = "response", print.matrix = FALSE)
> head(E.abund)
$fit
       1        2        3        4        5        6        7       
22.85038 22.90151 22.95177 23.00117 23.04969 23.09733 23.14408

> E.abund = as.data.frame(E.abund)
> E.abund$upper = E.abund$fit + (1.96 * E.abund$se.fit )
> E.abund$lower = E.abund$fit - (1.96 * E.abund$se.fit )
> E.abund    = cbind(E.abund, newData2)
>
> # predicting the abundance with an offset for survey area
> beta_fm10 = coef(fm10, type = "state")
>
> E.abund$mu = exp(E.abund$pred + log(300*max_dist)) * (1 - (exp(tpsi)/(1 + exp(tpsi))))

> E.abund$mu
  [1] 2.868877e+05 5.021370e+05 9.679519e+05 2.081259e+06 5.059868e+06
  [6] 1.411014e+07 4.581624e+07 1.759235e+08 8.114681e+08 4.567535e+09
 [11]


On Wed, Dec 4, 2013 at 6:24 PM, Alex Anderson <alejandro....@gmail.com> wrote:
Hi All,
apologies, the code above was from a previous test that did not include the offset.
please see below.  I think I have made an abovious istake:  my offset is on the detection, not the abundance process.  But when I try to predict with a model using an offset on abundance, I get an error because the transects varied between visits, not between sites.

>(fm1 <- pcount(~1 ~ MATemp2.time_step3 + offset(log(2*(distance*max_dist))),mixture = "ZIP",spp.umf,K = 60))
Error in offset(log(2 * (distance * max_dist))) :
  object 'distance' not found


Any ideas?
Cheers
A

correct code:

> (fm1 <- pcount(~1 +offset(log(2*(distance*max_dist))) ~ MATemp2.time_step3, mixture = "ZIP",spp.umf,K = 60))

Call:
pcount(formula = ~1 + offset(log(2 * (distance * max_dist))) ~
    MATemp2.time_step3, data = spp.umf, K = 60, mixture = "ZIP")

Abundance:
                   Estimate     SE      z P(>|z|)
(Intercept)          3.4466 0.0396 86.967   0.000
MATemp2.time_step3  -0.0113 0.0196 -0.577   0.564


Detection:
 Estimate     SE    z P(>|z|)
    -12.8 0.0414 -309       0


Zero-inflation:
 Estimate    SE     z  P(>|z|)
    -1.22 0.244 -5.01 5.32e-07

AIC: 4269.433
> E.psi = backTransform(fm1, type="psi")
> tpsi = E.psi@parentLinComb@estimate
> E.abund = predictSE.zip(fm1, newdata =newData2, se.fit = TRUE, parm.type = "lambda",

+                       type = "response", print.matrix = FALSE)
> head(E.abund)
$fit
       1        2        3        4        5        6        7       
22.85038 22.90151 22.95177 23.00117 23.04969 23.09733 23.14408

> E.abund = as.data.frame(E.abund)
> E.abund$upper = E.abund$fit + (1.96 * E.abund$se.fit )
> E.abund$lower = E.abund$fit - (1.96 * E.abund$se.fit )
> E.abund    = cbind(E.abund, newData2)
>
> # predicting the abundance with an offset for survey area
> beta_fm10 = coef(fm10, type = "state")
>
> E.abund$mu = exp(E.abund$pred + log(300*max_dist)) * (1 - (exp(tpsi)/(1 + exp(tpsi))))

> E.abund$mu
  [1] 2.868877e+05 5.021370e+05 9.679519e+05 2.081259e+06 5.059868e+06
  [6] 1.411014e+07 4.581624e+07 1.759235e+08 8.114681e+08 4.567535e+09
 [11]


Reply all
Reply to author
Forward
0 new messages