← Back to Code

Fitting a simple habitat suitability model

Overview

This is a short example vignette demonstrating how code, output, and figures can be embedded directly into a research page. Here, we simulate a simple presence/absence dataset and fit a logistic regression to estimate habitat suitability as a function of forest cover.

This is placeholder content to demonstrate the format — swap in real data and analysis for an actual project write-up.

Simulating example data

set.seed(42)
n <- 200
forest_cover <- runif(n, 0, 1)
linear_pred <- -2 + 5 * forest_cover
prob_presence <- 1 / (1 + exp(-linear_pred))
presence <- rbinom(n, 1, prob_presence)

data <- data.frame(forest_cover, presence)
head(data)
  forest_cover presence
1    0.9148060        1
2    0.9370754        1
3    0.2861395        0
4    0.8304476        1
5    0.6417455        1
6    0.5190959        1

Fitting the model

model <- glm(presence ~ forest_cover, data = data, family = binomial)
summary(model)
Call:
glm(formula = presence ~ forest_cover, family = binomial, data = data)

Coefficients:
             Estimate Std. Error z value Pr(>|z|)
(Intercept)   -2.0954     0.3403  -6.158 7.36e-10 ***
forest_cover   5.3781     0.6708   8.017 1.08e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 273.93  on 199  degrees of freedom
Residual deviance: 173.92  on 198  degrees of freedom
AIC: 177.92

Visualising the relationship

0.0 1.0 Forest cover (proportion)
Fig 1. Logistic regression fit of presence probability against forest cover (illustrative).

Interpretation

The fitted model suggests presence probability increases with forest cover, consistent with expectations for forest-dependent species. In a real write-up, this section would discuss model diagnostics, validation, and ecological interpretation in more depth.

Related Publications

Forthcoming.