# 1Galapagos Island Species Data

The Galapagos Islands about 600 miles off the coast of Ecuador provide an excellent laboratory for studying the factors that influence the development and survival of different life species. They were the site of much of Charles Darwin’s original research leading later to publication of his “Origin of Species”. Descending from a few stranded ancestors and cut off from the rest of the world, the Galapagos animals offer much more obvious proofs of the fact of evolution than can be seen in the more intricate complexities of life in most environments. Darwin wrote:

The natural history of these islands is eminently curious, and well deserves attention. Most of the organic productions are aboriginal creations, found nowhere else; there is even a difference between the inhabitants of the different islands; yet all show a marked relationship with those of America, though separated from that continent by an open space of ocean, between 500 and 600 miles in width. The archipelago is a little world in itself, or rather a satellite attached to America, whence it has derived a few stray colonists and has received the general character of its indigenous productions. Considering the small size of the islands, we feel the more astonished at the number of their aboriginal beings, and at their confined range. Seeing every height crowned with its crater, and the boundaries of most of the lava-streams still distinct, we are led to believe that within a period geologically recent the unbroken ocean was here spread out. Hence, both in space and time, we seem to be brought somewhere near to that great fact—that mystery of mysteries—the first appearance of new beings on earth.

And from elsewhere in Darwin’s diary: I never dreamed that islands 50 or 60 miles apart, and most of them in sight of each other, formed of precisely the same rocks, placed under a quite similar climate, rising to a nearly equal height, would have been differently tenanted… It is the circumstance that several of the islands possess their own species of the tortoise, mocking-thrush, finches and numerous plants, these species having the same general habits, occupying analogous situations, and obviously filling the same place in the natural economy of the archipelago, that strikes me with wonder.

M.P. Johnson and P.H. Raven, “Species number and endemism: The Galapagos Archipelago revisited”, Science, 179, 893-895 (1973), have presented data giving the number of plant species and related variables for 29 different islands. Counts are given for both the total number of species and the number of species that occur only in the Galapagos (the endemics). Elevations for Baltra and Seymour obtained from web searches. Elevations for four other small islands obtained from large-scale maps.

Variable    Description
Island      Name of Island
Plants      Number of plant species
PlantEnd    Number of endemic plant species
Finches     Number of finch species
FinchEnd    Number of endemic finch species
FinchGenera Number of finch genera
Area        Area (km^2)
Elevation   Maximum elevation (m)
Nearest     Distance from to nearest island (km)
StCruz      Distance to Santa Cruz Island (km)
Adjacent    Area of adjacent island (km^2)

Goal: To build a model to predict the proportion of endemic plants on an island based on the island characteristics.

fn.data <- "http://statacumen.com/teach/ADA2/homework/ADA2_HW_10_Galapagos.txt"
# to label plots in plots
gal$id <- 1:nrow(gal) Artificially remove the responses for three islands to predict later. # list of islands to predict island.pred.list <- c("Gardner2", "Santa.Fe", "Wolf") ## capture the observed probabilities gal.pred.true <- subset(gal, Island %in% island.pred.list) # Set these islands with missing response variables gal[(gal$Island %in% island.pred.list), c("Plants", "PlantEnd")] <- NA

Compute the observed proportion and empirical logits of endemic plants on each island.

# observed proportions
gal$p.hat <- gal$PlantEnd / gal$Plants # emperical logits gal$emp.logit <- log((gal$p.hat + 0.5/gal$Plants) /
(1 - gal$p.hat + 0.5/gal$Plants))

Data modifications

## RETURN HERE TO SUBSET AND TRANSFORM THE DATA

# gal <- subset(gal, !(X > Z))   # exclude observations of this type
# gal <- gal[!(gal$X > Z),] # exclude observations of this type ### SOLUTION ## 1.1(2 p) Interpret plot of observed proportions against predictors # Create plots for proportion endemic for each variable library(reshape2) gal.long <- melt(subset(gal, select = c(Island, id, p.hat, emp.logit, Area, Elevation, Nearest, StCruz, Adjacent)), id.vars = c("Island", "id", "p.hat", "emp.logit")) # Plot the data using ggplot library(ggplot2) p <- ggplot(gal.long, aes(x = value, y = p.hat, label = id)) p <- p + geom_hline(yintercept = c(0,1), alpha = 0.25) p <- p + geom_text(hjust = 0.5, vjust = -0.5, alpha = 0.25, colour = 2) p <- p + geom_point() p <- p + scale_y_continuous(limits = c(0, 1)) p <- p + facet_wrap( ~ variable, scales = "free_x", nrow = 1) print(p) # Plot the data using ggplot library(ggplot2) p <- ggplot(gal.long, aes(x = value, y = emp.logit, label = id)) p <- p + geom_text(hjust = 0.5, vjust = -0.5, alpha = 0.25, colour = 2) p <- p + geom_point() p <- p + facet_wrap( ~ variable, scales = "free_x", nrow = 1) print(p) Comment on how the proportion of endemic plants depends on each variable (in terms of increase/decrease). Also, interpret the plot regarding whether the empirical logits appear linear (or any trends). Note that the marginal empirical logit plots do not have to be linear, but the model in 6-dimensional space should be roughly “linear”. Indicate whether any observations are gross outliers and should be dropped, and whether variables are obvious candidates for transformation. Then, drop outliers, transform and update your comments, and repeat until satisfied. ### 1.1.1 Solution Proportion plots: [answer] Empirical logit plots: [answer] ## 1.2(0 p) Predictor scatterplot matrix For further information, the relationship between predictors is plotted. # relationships between predictors library(ggplot2) library(GGally) p <- ggpairs(subset(gal, select = c(Area, Elevation, Nearest, StCruz, Adjacent))) print(p) ## 1.3(1 p) Fit a logistic regression model, interpret deviance lack-of-fit Fit a logistic model relating the probability of endemic plants to the predictors. Decide which predictors to use.  ### SOLUTION # Don't include both Area and Elevation, since highly correlated glm.g.aensj <- glm(cbind(PlantEnd, Plants - PlantEnd) ~ Area + Nearest + StCruz + Adjacent, family = binomial, gal) # Test residual deviance for lack-of-fit (if > 0.10, little-to-no lack-of-fit) dev.p.val.full <- 1 - pchisq(glm.g.aensj$deviance, glm.g.aensj$df.residual) dev.p.val.full [1] 3.217315e-12 ## Stepwise selection # option: trace = 0 doesn't show each step of the automated selection glm.g.aensj.red.AIC <- step(glm.g.aensj, direction="both", trace = 0) # the anova object provides a summary of the selection steps in order glm.g.aensj.red.AIC$anova
        Step Df Deviance Resid. Df Resid. Dev      AIC
1            NA       NA        21   99.73305 208.5214
2 - Adjacent  1  1.72817        22  101.46122 208.2495
coef(glm.g.aensj.red.AIC)
  (Intercept)          Area       Nearest        StCruz
-8.357063e-01 -9.264229e-05 -6.121220e-03  3.490689e-03 
# Test residual deviance for lack-of-fit (if > 0.10, little-to-no lack-of-fit)
dev.p.val.red <- 1 - pchisq(glm.g.aensj.red.AIC$deviance, glm.g.aensj.red.AIC$df.residual)
dev.p.val.red
[1] 3.579248e-12

Look at the residual deviance lack-of-fit statistic for the full model. Is there evidence of any gross deficiencies with the model?

How about for the reduced model?

(Regardless of lack of fit result, continue with the assignment. This is a realistic example and not everything may work out nicely.)

Full:

Reduced:

## 1.4(2 p) Interpret logistic regression coefficients

Which variables appear to be a useful predictor of the probability of endemic plants? Interpret the hypothesis test(s).

summary(glm.g.aensj.red.AIC)

Call:
glm(formula = cbind(PlantEnd, Plants - PlantEnd) ~ Area + Nearest +
StCruz, family = binomial, data = gal)

Deviance Residuals:
Min      1Q  Median      3Q     Max
-3.382   0.223   1.182   2.063   4.056

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -8.357e-01  7.642e-02 -10.935  < 2e-16 ***
Area        -9.264e-05  3.173e-05  -2.920  0.00350 **
Nearest     -6.121e-03  3.341e-03  -1.832  0.06694 .
StCruz       3.491e-03  1.333e-03   2.619  0.00881 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 119.39  on 25  degrees of freedom
Residual deviance: 101.46  on 22  degrees of freedom
(3 observations deleted due to missingness)
AIC: 208.25

Number of Fisher Scoring iterations: 3

### 1.4.1 Solution

XXX is significant and it’s negative coefficient of -9.2610^{-5} suggests that as XXX increases, the proportion of endemic plants decreases.

etc.

## 1.5(1 p) Write model equation

Provide an equation relating the fitted probability of endemic plants to the selected predictor variables on the probability scale.

### 1.5.1 Solution

The logistic equation is $\tilde{p} = \frac{ \exp( XXX )} { 1 + \exp( XXX ) } .$

## 1.6(2 p) Plot the fitted probabilities as a function of the selected predictor variables.

Note that if there are more than one predictor, these plots may be jagged. That is because the predictions we’re getting for each observation is conditional on the other variables in the model. This is not an ideal way of plotting the data and model, but it will give some sense of whether the predictions are close to the observed proportions.

# put the fitted values in the data.frame
#gal$fitted.values <- glm.g.aensj.red.AIC$fitted.values
# predict() uses all the Load values in dataset, including appended values
fit <- predict(glm.g.aensj.red.AIC, subset(gal, select = c(Area, Elevation, Nearest, StCruz, Adjacent)), type = "link", se.fit = TRUE)
gal$fit <- fit$fit
gal$se.fit <- fit$se.fit
# CI for fitted values
gal <- within(gal, {
fitted    = exp(fit) / (1 + exp(fit))
fit.lower = exp(fit - 1.96 * se.fit) / (1 + exp(fit - 1.96 * se.fit))
fit.upper = exp(fit + 1.96 * se.fit) / (1 + exp(fit + 1.96 * se.fit))
})

### 1.6.1 Solution

{R, fig.height = 4, fig.width = 10}
library(ggplot2)
p1 <- ggplot(gal, aes(x = XXX, y = p.hat))
# predicted curve and point-wise 95% CI
p1 <- p1 + geom_ribbon(aes(x = XXX, ymin = fit.lower, ymax = fit.upper), alpha = 0.2)
p1 <- p1 + geom_line(aes(x = XXX, y = fitted), colour="red")
# fitted values
p1 <- p1 + geom_point(aes(y = fitted), size=2, colour="red")
# observed values
p1 <- p1 + geom_point(size = 2)
p1 <- p1 + scale_y_continuous(limits = c(0,1))
p1 <- p1 + ylab("Probability")
#p1 <- p1 + labs(title = "Observed and predicted probability of endemic")
#print(p1)

library(ggplot2)
p2 <- ggplot(gal, aes(x = XXX, y = p.hat))
# predicted curve and point-wise 95% CI
p2 <- p2 + geom_ribbon(aes(x = XXX, ymin = fit.lower, ymax = fit.upper), alpha = 0.2)
p2 <- p2 + geom_line(aes(x = XXX, y = fitted), colour="red")
# fitted values
p2 <- p2 + geom_point(aes(y = fitted), size=2, colour="red")
# observed values
p2 <- p2 + geom_point(size = 2)
p2 <- p2 + scale_y_continuous(limits = c(0,1))
p2 <- p2 + ylab("Probability")
#p2 <- p2 + labs(title = "Observed and predicted probability of endemic")
#print(p2)

library(gridExtra)
grid.arrange(grobs = list(p1, p2), nrow=1, top = "Observed and predicted probability of endemic")

## 1.7(1 p) Interpret the prediction with 95% CI at the three islands we didn’t use to build the model

Compute the estimated probability of endemic for these islands:

island.pred.list
[1] "Gardner2" "Santa.Fe" "Wolf"    

Provide and interpret the 95% CIs for this probability.

We have already augmented the data set with the values to predict, so the predict() function above has already done the calculations for us.