if (FALSE) {
### ANOVA example for Goodall's F test (multivariate shape vs. factors)
data(plethodon)
Y.gpa <- gpagen(plethodon$land) #GPA-alignment
gdf <- geomorph.data.frame(Y.gpa,
site = plethodon$site,
species = plethodon$species) # geomorph data frame
fit1 <- procD.lm(coords ~ species * site,
data = gdf, iter = 999, turbo = TRUE,
RRPP = FALSE, print.progress = FALSE) # randomize raw values
fit2 <- procD.lm(coords ~ species * site,
data = gdf, iter = 999, turbo = TRUE,
RRPP = TRUE, print.progress = FALSE) # randomize residuals
summary(fit1)
summary(fit2)
# RRPP example applications
coef(fit2)
coef(fit2, test = TRUE)
anova(fit2) # same as summary
anova(fit2, effect.type = "Rsq")
# if species and site were modeled as random effects ...
anova(fit2, error = c("species:site", "species:site", "Residuals"))
# not run, because it is a large object to print
# remove # to run
# predict(fit2)
# TPS plots for fitted values of some specimens
M <- Y.gpa$consensus
plotRefToTarget(M, fit2$GM$fitted[,,1], mag = 3)
plotRefToTarget(M, fit2$GM$fitted[,,20], mag = 3)
### THE FOLLOWING ILLUSTRATES SIMPLER SOLUTIONS FOR
### THE NOW DEPRECATED advanced.procD.lm FUNCTION AND
### PERFORM ANALYSES ALSO FOUND VIA THE morphol.disparity FUNCTION
### USING THE pairwise FUNCTION
# Comparison of LS means, with log(Csize) as a covariate
# Model fits
fit.null <- procD.lm(coords ~ log(Csize) + species + site, data = gdf,
iter = 999, print.progress = FALSE, turbo = TRUE)
fit.full <- procD.lm(coords ~ log(Csize) + species * site, data = gdf,
iter = 999, print.progress = FALSE, turbo = TRUE)
# ANOVA, using anova.lm.rrpp function from the RRPP package
# (replaces advanced.procD.lm)
anova(fit.null, fit.full, print.progress = FALSE)
# Pairwise tests, using pairwise function from the RRPP package
gp <- interaction(gdf$species, gdf$site)
PW <- pairwise(fit.full, groups = gp, covariate = NULL)
# Pairwise distances between means, summarized two ways
# (replaces advanced.procD.lm):
summary(PW, test.type = "dist", confidence = 0.95, stat.table = TRUE)
summary(PW, test.type = "dist", confidence = 0.95, stat.table = FALSE)
# Pairwise comaprisons of group variances, two ways
# (same as morphol.disaprity):
summary(PW, test.type = "var", confidence = 0.95, stat.table = TRUE)
summary(PW, test.type = "var", confidence = 0.95, stat.table = FALSE)
morphol.disparity(fit.full, groups = gp, iter = 999)
### Regression example
data(ratland)
rat.gpa <- gpagen(ratland) #GPA-alignment
gdf <- geomorph.data.frame(rat.gpa) # geomorph data frame is easy
# without additional input
fit <- procD.lm(coords ~ Csize, data = gdf, iter = 999, turbo = TRUE,
RRPP = TRUE, print.progress = FALSE)
summary(fit)
### Extracting objects and plotting options
# diagnostic plots
plot(fit, type = "diagnostics")
# diagnostic plots, including plotOutliers
plot(fit, type = "diagnostics", outliers = TRUE)
# PC plot rotated to major axis of fitted values
plot(fit, type = "PC", pch = 19, col = "blue")
# Regression-type plots
# Use fitted values from the model to make prediction lines
plot(fit, type = "regression",
predictor = gdf$Csize, reg.type = "RegScore",
pch = 19, col = "green")
# Uses coefficients from the model to find the projected regression
# scores
rat.plot <- plot(fit, type = "regression",
predictor = gdf$Csize, reg.type = "RegScore",
pch = 21, bg = "yellow")
# TPS grids for min and max scores in previous plot
preds <- shape.predictor(fit$GM$fitted, x = rat.plot$RegScore,
predmin = min(rat.plot$RegScore),
predmax = max(rat.plot$RegScore))
M <- rat.gpa$consensus
plotRefToTarget(M, preds$predmin, mag=2)
plotRefToTarget(M, preds$predmax, mag=2)
attributes(fit)
fit$fitted[1:3, ] # the fitted values (first three specimens)
fit$GM$fitted[,, 1:3] # the fitted values as Procrustes
# coordinates (same specimens)
### THE FOLLOWING ILLUSTRATES SIMPLER SOLUTIONS FOR
### THE NOW DEFUNCT nested.update FUNCTION USING
### THE anova GENERIC FUNCTION
data("larvalMorph")
Y.gpa <- gpagen(larvalMorph$tailcoords,
curves = larvalMorph$tail.sliders,
ProcD = TRUE, print.progress = FALSE)
gdf <- geomorph.data.frame(Y.gpa, treatment = larvalMorph$treatment,
family = larvalMorph$family)
fit <- procD.lm(coords ~ treatment/family, data = gdf, turbo = TRUE,
print.progress = FALSE, iter = 999)
anova(fit) # treatment effect not adjusted
anova(fit, error = c("treatment:family", "Residuals"))
# treatment effect updated (adjusted)
}
Run the code above in your browser using DataLab