Analysis with R: Assignment 1

Submit your assignment for the Analysis module in a reply to this topic

Remember to include these five elements:

  1. A model selection table :1234: with three detection functions
  2. A plot :bar_chart: of one of your detection functions
  3. Interpretation :bulb: What conclusion do your draw from your results?
  4. A brief reflection :thinking: on your next step, challenge you solved, problem you still have or leap of understanding
  5. Give specific and useful feedback :thumbsup: to a coursemate

Remember that each written step need only be a sentence or two

2 posts were split to a new topic: Installing R, RStudio & packages

There are three detection functions, see table below

Detection function Hypothesis Use cases
Uniform Detection decreases gradually with increase in distance Open grassland, open water
Half normal Detection declines propotionallly with increase in distanced to give a in a smooth curve Open woodlands/shrublands, undulating land
Hazard rate Detection declines very sharply with increase in distance Dense forest, bamboo, steep slopes or narrow valleys

Code:
hn_NullH ← distsamp(
~1 ~1,
distUMF,
keyfun=“hazard”,
output=“density”,
unitsOut=“ha”)
hn_NullH # show distance model output
hist(hn_NullH)

Interpretation:

I ran the detection and density function.
Using the hazard-rate model , It would seem that there are 2.1 Chinese water deer per square km.
This please note was at a standard error of NA.
Even calculating the 95% confidence interval gave NA.
It also gave a detection probability of 98%.
The AIC was 507.9647, higher than the half norm.

Reflection;

I was trying too combine all three and compare their AIC’s, i cant get the code to work,

The code

models ← list(
hn… = hn_NullT, # hn… is the model name in our list
unif… = unif_NullT,
haza… = hn_NullH)
fmList ← fitList(fits = models)

Error i get

fmList ← fitList(fits = models)
Error in validityMethod(object) :
Data are not the same among models. Make sure you use the same unmarkedFrame object for all models.

Though all the three models are Formal class unmarked fitds

This is a great start, Nicorrl!

This error means that your models weren’t all built on the same data, meaning that any comparisons using Information Theory/AIC aren’t valid

:warning: Did you run some models on the truncated dataset, and some on the original data?

The maximum distance on your histogram suggests that particular model was run on untruncated data. The flat line plotted for the detection function suggests it’s actually the uniform model. You may need to check through your code, and in particular the object names, to be sure you’re passing in comparable models to fitList()

  1. Model selection table
      nPars              AIC          delta         AICwt        cumltvWt
hz..       3           352.00         0.00         9.9e-01         0.99
hn..       2           361.13         9.13         1.0e-02         1.00
unif..     1           404.98        52.98        3.1e-12         1.00
  1. Plot attached

  2. If I understand the theory correctly, the model that best fits our data is the one with the lowest AIC, and lowest DeltaAIC therefore according to the model selection table that would be our hazard model.
    The hazard model results in a density of 0.106 water deer per ha, therefore 10 deer per square kilometre. The 95% confidence interval spans 0.05 to 0.24.

The detectability of water deer is 20.1m and standard deviation is also high 20.4.

After calculating the confidence intervals I am not sure how to extrapolate the following data to calculate the range at which the deer will be observed:

Backtransformed linear combination(s) of Detection estimate(s)

Estimate SE LinComb (Intercept)
20.1 20.4 3 1

Transformation: exp

DetCI ← confint(DetEst)
DetCI
0.025 0.975
2.742069 147.5237

I addition, when trying to do the histogram of the hazard model, it gave me issues: *Error in integrate(gxhaz, 0, Inf, shape = shape, scale = scale) : the integral is probably divergent.

  1. Challenge:
    At the moment I don’t really understand how to read the plot from the hazard model. I also used the same code for the exp model, and a similar issue happened with the histogram.
    Rplot_hz_NullT

modsel

Based on the model selection table above we can see that the best-supported model is the model that uses the hazard-rate detection function, as that model has the lowest AIC and a delta of 0.

The model estimates the density of 0.106 water deer per hectar or 10 water per square km.

The effective half-strip width is 25.2m of our deer transects and our detection probability (EHSW/220) is 11%.

Challenges/queries:

I was unable to get a histogram for hazard-rate

hist(hazard_NullT)

Error in integrate(gxhaz, 0, Inf, shape = shape, scale = scale) :
the integral is probably divergent

and

I wasn’t sure how to interpret the detectability estimate. Does the hazard-rate detection function have the same properties as normal and half-normal?

I had the same error code for the hazard-rate histogram.

1 Like

Matt, could you explain your calculation of ESWH? finding difficult to get those results.

Thank you.

I adapted the code from the ‘calculate effective strip half width’ slide and changed the distance from 350 to 220 because that was new distance after we truncated the data.

ESHWHaz ← integrate(gxhn,
0,
220,
sigma = DetEstHaz@estimate)

and did the same with the code from the following slide

ESHWHaz$value / 220

I just followed the same code/method as we did with the pre-truncated data. But I did think that the output seemed low at only 11% detection probability, so not 100% sure I did it correctly.

I’d be interested to see how the code works for you.

1 Like

Thanks Matt,

I was rather working with density, not detectability, therefore numbers were different.

Detectability ESWH

ESWH_hz_det ← integrate(gxhn,
0,
220,
sigma = DetEstT3@estimate)
ESWH_hz_det
25.20751 with absolute error < 5.6e-08
ESWH_hz_det$value / 220
[1] 0.1145796

11.45% probability to be detected.

Model Selection Table with the values for three detection functions for Chinese Water Deer Data:
image

To interpret the AIC from the three detection functions, Uniform>Half Normal>Hazard rate. Therefore, my understanding is that the hazard rate would be the best detection function for analyzing this data. But I couldn’t get R to plot the hazard rate histogram. I hope to try again.
Here’s the one for uniform:

That’s the correct interpretation, @Nuria

Bear in mind that these model rankings may change as you begin to include hypotheses with covariates, in the next module

Thank you for this,

I have incorporated the fixes, (but used the Lemur data instead )

       nPars    AIC  delta   AICwt cumltvWt
Lhz_NullT     3 667.26   0.00 8.8e-01     0.88
Lhn_NullT     2 671.28   4.02 1.2e-01     1.00
Lun_NullT     1 968.69 301.44 3.1e-66     1.00

Plots(i plotted both the half norm and hazard detection functions , just to see because of their close AIC.

Figure 1.Lemur survey data, half normal detection function

Figure 2.Lemur sightings data, hazard detection data

Interpretation
The halfnorm detection model has the least AIC. The halfnorm model results in a density of 1.75 lemur per ha, therefore 175 lemur per km2. The 97% confidence interval spans from 1.57 to 1.96. The detectability of water deer is 11.3m.
The effective half-strip width is 14.1m of our lemur transects and our detection probability (EHSW/30) is 47%.

1 Like

Thanks for sharing a working example of the hazard rate model and visual comparison :raised_hands:

I’ve added some explanation as to why the hazard-rate model is not providing a graph in our course discussion area here: Problems with Hazard-rate histogram

I’ve also added an explanation of the two hazard rate parameters (shape and scale), and an example of using uneven distance bins/histogram breaks to make it easier to fit a detection function to a dataset with low sightings

Given this difficulty, I’m awarding a badge to all of you who attempted this assignment and interpretation of your results