Some code from Week 7 Worked Example for profiling.

library(LandGenCourse)
library(nlme)
library(dplyr)
library(spatialreg)
library(ggplot2)
library(tmap)

a) Import data

data(Dianthus)
Dianthus.df <- data.frame(A=Dianthus$A, IBD=Dianthus$Eu_pj, 
                          IBR=Dianthus$Sheint_pj,
                          PatchSize=log(Dianthus$Ha),
                          System=Dianthus$System,
                          Longitude=Dianthus$Longitude,
                          Latitude=Dianthus$Latitude,
                          st_coordinates(Dianthus))

# Define 'System' for ungrazed patches
Dianthus.df$System=as.character(Dianthus$System)
Dianthus.df$System[is.na(Dianthus.df$System)] <- "Ungrazed"
Dianthus.df$System <- factor(Dianthus.df$System, 
                             levels=c("Ungrazed", "East", "South", "West"))

# Remove patches with missing values for A
Dianthus.df <- Dianthus.df[!is.na(Dianthus.df$A),]
dim(Dianthus.df)

b) Fit regression models

Here we fit three multiple regression models to explain variation in allelic richness:

mod.lm.IBD <- lm(A ~ IBD, data = Dianthus.df)
summary(mod.lm.IBD)

This model does not fit the data at all!

mod.lm.IBR <- lm(A ~ IBR, data = Dianthus.df)
summary(mod.lm.IBR)


hhwagner1/LandGenCourse documentation built on Feb. 17, 2024, 4:42 p.m.