Day 1 · Assessed problem set

Probability and discrete distributions in ecology

Your graded 40-point Day 1 assignment: six morning probability problems and six afternoon distribution problems, drawn from marine, terrestrial, and wildlife-disease systems. Two problems use small real datasets you load into R.

This is the assessed problem set — answers are not shown here. Write your work in the two R Markdown hand-in templates: morning_lab_template.Rmd for the morning problems (1–6) and afternoon_lab_template.Rmd for the afternoon problems (7–12). Knit each to HTML and upload to the matching Canvas assignment.

For worked-example study with visible answers, use the in-class practice lab. Need R Markdown help? See the R Markdown tutorial.

Two problems use small datasets — download them from the Datasets panel below and keep them in a data/ folder beside your .Rmd so the read.csv() calls resolve. Work each problem in the matching template, knit to HTML, and submit on Canvas.

Datasets for this assignment

Click a file to download it, then put it in a data/ subfolder beside your .Rmd so the read.csv() calls resolve.

edna_carp_results.csvqPCR eDNA replicate results for 12 candidate lakes (columns: lake, replicate, positive). Problem 2.
coyote_scat_counts.csvCoyote scat counts on 120 grid cells (columns: grid_id, transect, scats). Problem 9.
Morning · 20 pts

Probability problems

Sample-space reasoning, conditional probability, Bayes' rule, expectation, and variance algebra — using only the probability tools from the morning session (no named distributions yet; those come this afternoon). Work each on paper first, then confirm numerically in R inside morning_lab_template.Rmd.

Problem 1 · conditional probability

Acoustic detection of tagged steelhead

A tagged steelhead passes through a river reach monitored by two independent acoustic receivers. Given the fish is present, each receiver detects the tag with probability $0.85$. If the fish is absent, false detections are negligible.

  1. Given the fish is present, what is the probability that at least one receiver detects it?
  2. Given that at least one receiver detected the fish, what is the probability that both receivers detected it?
  3. Why is your answer to (b) different from $0.85$? Answer in one or two sentences.
Your answer goes in the R Markdown hand-in. Put your reasoning and any R checks in morning_lab_template.Rmd under Problem 1.
Problem 2 · Bayes' rule · uses data

eDNA detection of invasive carp

An agency screens candidate lakes for bighead carp using an environmental-DNA (eDNA) qPCR assay. Based on the surrounding watershed, the prior probability that carp are present in any given lake is $0.20$. The assay has sensitivity $P(+\mid\text{present}) = 0.92$ and specificity $P(-\mid\text{absent}) = 0.97$ (so the false-positive rate is $0.03$).

  1. A single sample from a lake comes back positive. What is the posterior probability that carp are present?
  2. If two independent samples from the same lake both come back positive, what is the posterior? (Update sequentially: the posterior after the first sample becomes the prior for the second.)
  3. How much does the answer to (a) change if the prior is $0.02$ instead of $0.20$? What does this say about screening rare invaders?
  4. The file data/edna_carp_results.csv holds the qPCR replicate results for 12 candidate lakes (columns lake, replicate, positive, where positive is 1/0). Load it, and for each lake compute the posterior probability of carp presence by starting from the $0.20$ prior and updating once per replicate (a positive replicate updates with sensitivity/false-positive-rate; a negative replicate updates with the miss rate $1-0.92$ and specificity $0.97$). Which lakes end up with posterior probability above $0.95$? Which fall below $0.05$?
Swap "carp present" for any rare cryptic species and "eDNA assay" for an AI-classified camera-trap detector: when the base rate is low, even an accurate test produces mostly false alarms. Replicate sampling is how field programs claw the posterior back toward certainty.
Load the data
edna <- read.csv("data/edna_carp_results.csv")
head(edna)
# one row per qPCR replicate; positive = 1 (detection) or 0 (no detection)
Your answer goes in the R Markdown hand-in. Do parts (a)–(c) with pencil-and-paper reasoning plus an R check, and write the per-lake update in (d) as a small loop or function in morning_lab_template.Rmd.
Problem 3 · expectation & variance algebra

Combining two survey indices

Two independent survey methods estimate deer abundance at a site. An aerial count $X$ has mean $E[X] = 40$ and standard deviation $6$ (so $\mathrm{Var}(X) = 36$). A ground transect $Y$ has mean $E[Y] = 30$ and standard deviation $8$ (so $\mathrm{Var}(Y) = 64$). Treat $X$ and $Y$ as independent. Use only the algebra of expectation and variance from this morning: $E[aX + b] = aE[X] + b$, $\mathrm{Var}(aX + b) = a^2\,\mathrm{Var}(X)$, and $\mathrm{Var}(X + Y) = \mathrm{Var}(X) + \mathrm{Var}(Y)$ when $X$ and $Y$ are independent.

  1. A calibration corrects a known aerial bias: $X_c = 1.2\,X - 3$. Find $E[X_c]$ and $\mathrm{Var}(X_c)$ (and the SD).
  2. The two methods are combined into a total index $T = X + Y$. Find $E[T]$ and $\mathrm{Var}(T)$.
  3. A weighted index is formed as $I = 0.6\,X + 0.4\,Y$. Find $E[I]$ and $\mathrm{Var}(I)$. Is its variance larger or smaller than that of the total $T$, and why?
  4. Suppose $X$ and $Y$ were in fact positively correlated (good survey conditions inflate both). Which of your variance answers in (b) and (c) would be wrong, and would the true variance be larger or smaller than what you computed? One or two sentences — no calculation needed.
Almost every abundance estimate is a function of other random quantities — sums, differences, calibrated and weighted combinations. Knowing how means and variances flow through those operations (and how independence, or its absence, changes the variance) is the algebra behind every error bar you will report.
Your answer goes in the R Markdown hand-in. Show each expectation and variance step in morning_lab_template.Rmd under Problem 3.
Problem 4 · expected value via indicators

Isolated callers along a ridgeline

$n = 30$ cougar territories are arranged linearly along a ridgeline. Each cougar independently has probability $p = 0.3$ of calling on a given night. Define an isolated caller as a cougar that calls while neither immediate neighbor calls. Consider only the 28 interior cougars (positions $2$ through $29$), which have two neighbors each.

  1. Using indicator variables and linearity of expectation, compute the expected number of isolated callers. (Write $X = \sum_i X_i$ where $X_i = 1$ if cougar $i$ is an isolated caller.)
  2. Verify your answer by simulation with 20,000 replicate nights.
  3. Would the expected value in (a) change if calling events were positively correlated between neighbors (as they often are)? Which of your two arguments — the expectation or a variance calculation — would be affected? One or two sentences.
The indicator trick — break a complicated count into a sum of simple 0/1 pieces, then add their expectations — is one of the most reusable moves in ecology: expected number of local-maximum nest sites, of solitary singers, of runs in a track survey, and more.
Your answer goes in the R Markdown hand-in. Show the indicator argument and the simulation check in morning_lab_template.Rmd.
Problem 5 · total probability + Bayes

Grizzly bear DNA from hair snares

A hair-snare grid has 40 stations. At a station where a bear is actually present, the probability of collecting at least one usable hair sample in one visit is $p = 0.18$; where no bear is present, no usable sample is collected. Bears are present at $60\%$ of stations.

  1. For a randomly chosen station, what is the probability of collecting at least one usable sample in one visit? (Condition on presence — this is the law of total probability.)
  2. Given that a station did yield at least one sample, what is the probability a bear was present there? Explain why the answer takes the value it does.
  3. If you visit every station three times (visits independent given presence), what is the per-station probability of at least one sample across the three visits — both conditional on presence, and marginally over presence?
Detection is conditional on presence, and presence is uncertain. Nearly every occupancy and capture–recapture model in the course is built on exactly this two-layer structure: a process that decides presence, and a detection process laid on top of it.
Your answer goes in the R Markdown hand-in. Lay out the conditioning and the arithmetic in morning_lab_template.Rmd under Problem 5.
Problem 6 · expected value + probability rules

Fishers vote on a regulation

Twenty commercial fishers vote on a proposed regulation. Each votes "yes" independently with probability $0.4$.

  1. Treat the number of yes votes as a sum of twenty independent $0/1$ votes. Using linearity of expectation (and the fact that variances of independent things add), find the expected number of yes votes and its variance. (You do not need any named distribution — just $E$ and $\mathrm{Var}$ of a sum.)
  2. Two specific fishers, Ana and Ben, vote independently. Using the multiplication and addition rules, find (i) the probability both vote yes, (ii) the probability at least one votes yes, and (iii) the probability exactly one votes yes.
  3. You then learn that Ana voted yes. Does that change the probability that Ben votes yes? Answer in one sentence, referring to the definition of independence.
The expected value of a sum, and the multiplication/addition rules for independent events, are the two workhorses of everyday probability — behind quorum counts, joint detection probabilities, and "at least one" calculations throughout ecology. (Next session you will package this exact "count of independent yes/no events" into the Binomial distribution.)
Your answer goes in the R Markdown hand-in. Report the mean and variance and the three joint probabilities in morning_lab_template.Rmd.
Afternoon · 20 pts

Discrete-distribution problems

Bernoulli/Binomial, Poisson, Negative Binomial, and Multinomial — each one a story about how counts are generated. Work these in afternoon_lab_template.Rmd.

Problem 7 · Binomial

Sea turtle nest success

A monitored loggerhead beach has $n = 18$ nests, each hatching successfully with probability $p = 0.62$, independently.

  1. Write the data-generating model, then give the expected number of successful nests and the variance.
  2. What is the probability of exactly 12 successful nests?
  3. What is the probability of at least 15 successful nests?
  4. If a beach manager wanted at least an $80\%$ chance of seeing $\ge 15$ successes, what would the per-nest success probability $p$ need to be? Find it numerically.
Your answer goes in the R Markdown hand-in. Use dbinom/pbinom and report values in afternoon_lab_template.Rmd under Problem 7.
Problem 8 · Poisson

Wolf approaches at an active den

An observer records wolf approaches to a den at an average rate of $\lambda = 1.8$ per 12-hour observation period.

  1. Write the model. What does it assume about the independence of successive approaches, and where might that assumption fail in the field?
  2. What is the probability of no approaches in a 12-hour period?
  3. What is the probability of more than 3 approaches in a 12-hour period?
  4. What is the probability of exactly 5 approaches in a 36-hour period? (Scale $\lambda$ with the observation window.)
The Poisson is the natural distribution for independent, rare-ish events occurring at a steady rate in a fixed window of time or space. Its single-parameter rigidity (mean = variance) is exactly what real, clustered data violate — which motivates the next problem.
Your answer goes in the R Markdown hand-in. Use dpois/ppois and note the rate-scaling in part (d).
Problem 9 · Poisson vs Negative Binomial · uses data

Coyote scat counts: is Poisson enough?

The file data/coyote_scat_counts.csv holds coyote scat counts from a recent survey of 120 grid cells (columns grid_id, transect, scats). You will decide whether a Poisson or a Negative Binomial model fits these counts.

  1. Load the data. Compute the sample mean and variance of scats. What do you notice, and what does it suggest about the Poisson assumption that mean = variance?
  2. Find the Negative Binomial dispersion parameter $k$ (R's size) by the method of moments. (The method of moments is just this: write down the distribution's theoretical mean and variance in terms of its unknown parameters, set them equal to the sample mean and variance you measured, and solve. Here the Negative Binomial has mean $\mu$ and variance $\mathrm{Var}(Y) = \mu + \mu^2/k$; setting that equal to the observed variance and solving gives $k = \mu^2 / (\mathrm{Var}(Y) - \mu)$.) Compute $k$ from your sample moments.
  3. Compare the observed $P(Y = 0)$ and $P(Y > 15)$ in the data against the values predicted by (i) a Poisson with the sample mean, and (ii) a Negative Binomial with the sample mean and your fitted $k$. Which distribution reproduces the data?
  4. Plot a histogram of the counts and overlay the Poisson and NB pmfs. In one or two sentences, name an ecological mechanism that could produce this over-dispersion.
Animals cluster — territories, latrines, family groups, patchy resources. That clustering pushes variance above the mean, and the Negative Binomial is the "Poisson with a built-in clumping mechanism." Diagnosing over-dispersion from data is one of the most common moves you will make all week.
Load the data
coyote <- read.csv("data/coyote_scat_counts.csv")
str(coyote)
mu  <- mean(coyote$scats)
v   <- var(coyote$scats)
c(mean = mu, variance = v)
Your answer goes in the R Markdown hand-in. Report the moments, fitted $k$, the three-way comparison, and the plot in afternoon_lab_template.Rmd under Problem 9.
Problem 10 · Multinomial

Owl pellet contents

Barn owl pellets from a regional diet study are composed of voles $0.65$, shrews $0.20$, mice $0.10$, and birds $0.05$.

Simplifying assumption. Real pellets contain different numbers of items, but for this problem assume every pellet contains exactly 15 identifiable prey items. That fixes the total $n = 15$, so a pellet's contents follow a Multinomial$(n = 15,\ \mathbf{p})$. Parts (c) and (d) below hold this assumption; part (c) in particular treats all 50 pellets as having 15 items each.
  1. For a pellet with 15 items, what is the probability of the exact composition $(10, 3, 1, 1)$ — 10 voles, 3 shrews, 1 mouse, 1 bird?
  2. What is the marginal distribution of the number of shrews in a single 15-item pellet? Give its name, mean, and variance.
  3. Assuming each of 50 pellets contains 15 items, what is the expected total number of mice across all 50 pellets?
  4. Simulate 5,000 fifteen-item pellets and confirm that the marginal count of one category (your choice) matches the binomial you named in (b).
The Multinomial is the distribution for "$n$ items sorted into $k$ mutually exclusive categories." A key fact you will reuse: any single category of a Multinomial is, on its own, Binomial — which is why diet, habitat-use, and survey-response data can be analyzed one category at a time when convenient.
Your answer goes in the R Markdown hand-in. Use dmultinom and rmultinom in afternoon_lab_template.Rmd under Problem 10.
Problem 11 · mixed Poisson / over-dispersion

Pooling counts across sites creates over-dispersion

Counts of microplastic particles per mussel follow a Poisson distribution, but the rate differs by site: at site A, $\lambda_A = 2$; at site B, $\lambda_B = 8$. You collect 50 mussels from each site and then pool them into a single sample of 100.

  1. If you (incorrectly) treat the pooled sample as one Poisson sample, what mean and variance would you estimate? Will the pooled distribution actually be Poisson? Explain why or why not.
  2. Show by simulation that the pooled distribution is over-dispersed (variance noticeably greater than mean).
  3. Now derive the pooled mean and variance exactly, step by step — you only need the definitions of mean and variance from this morning, no new theorem. A randomly chosen mussel from the pooled sample came from site A (rate $\lambda = 2$) or site B (rate $\lambda = 8$), each with probability $\tfrac12$. Work out $E[Y]$ and $\mathrm{Var}(Y)$ for that randomly chosen mussel, then check your two numbers against your simulation from (b) and compare the variance to what a real Poisson with the same mean would have required.
    Scaffolding, if you need it. Average each quantity over the two sites. The mean is a direct average of the two site means. For the variance, you cannot average the two site variances — go through the second moment instead: for a single Poisson$(\lambda)$, $\mathrm{Var} = E[Y^2] - (E[Y])^2 = \lambda$, so $E[Y^2 \mid \lambda] = \lambda + \lambda^2$. Average that over the two sites to get $E[Y^2]$, then use $\mathrm{Var}(Y) = E[Y^2] - (E[Y])^2$.
  4. In one or two sentences: what does this exercise tell you about why real count data are over-dispersed even when the process is Poisson within each homogeneous unit?
This is the mechanism behind the Negative Binomial itself: a Poisson whose rate varies (here across two sites; in the NB, continuously via a gamma distribution). Unmodeled heterogeneity in the rate is the single most common source of over-dispersion in ecological counts.
Your answer goes in the R Markdown hand-in. Give the simulation and the total-variance derivation in afternoon_lab_template.Rmd under Problem 11.
Problem 12 · Binomial · surveillance design

Disease surveillance sample size

A herd has a hypothetical brucellosis prevalence of $0.15$. You will sample $n$ animals independently and test each. You want at least a $95\%$ probability of detecting at least one positive animal.

  1. Write the binomial probability of detecting at least one positive in a sample of $n$, and set up the inequality that guarantees $95\%$ detection power.
  2. Solve for the smallest $n$ that delivers $95\%$ detection probability — algebraically using logs, and confirm in R.
  3. Repeat for a prevalence of $0.02$. Comment on how required sample size scales as the disease becomes rarer.
"Freedom from disease" and rare-species-detection sample-size calculations are exactly this computation. The same $1 - (1-p)^n \ge 0.95$ logic sizes the effort needed to be confident you would have caught something if it were there.
Your answer goes in the R Markdown hand-in. Show the inequality, the closed-form $n$, and the R confirmation in afternoon_lab_template.Rmd under Problem 12.