knitr::opts_chunk$set(echo = TRUE)
library(SCGLR)

# load sample data
data(genus)

# get variable names from dataset
n <- names(genus)
ny <- n[grep("^gen",n)]    # Y <- names that begins with "gen"
nx <- n[-grep("^gen",n)]   # X <- remaining names

# remove "geology" and "surface" from nx
# as surface is offset and we want to use geology as additional covariate
nx <-nx[!nx%in%c("geology","surface")]

# build multivariate formula
# we also add "lat*lon" as computed covariate to catch spatial spatial patterns
form <- multivariateFormula(ny,c(nx,"I(lat*lon)"),A=c("geology"))

# define family
fam <- rep("poisson",length(ny))

genus.scglr <- scglr(formula=form,data = genus,family=fam, K=4,
 offset=genus$surface)

Display a summary of results

summary(genus.scglr)

Percent of variance captured by components

screeplot(genus.scglr)

Correlation plot for first two components

plot(genus.scglr, title="Correlation plot showing covariates")
plot(genus.scglr,predictors=TRUE,covariates=FALSE, title="Correlation plot showing predictors")

Comparing combinations of components

pairs(genus.scglr,ncol=2)

Using grouped covariates (theme)

n <- names(genus)
n <-n[!n%in%c("geology","surface","lon","lat","forest","altitude")]
ny <- n[grep("^gen",n)]    # Y <- names that begins with "gen"
nx1 <- n[grep("^evi",n)]   # theme 1 with EVI covariates
nx2 <- n[-c(grep("^evi",n),grep("^gen",n))] # theme 2 with pluviometry covariates

form <- multivariateFormula(ny,nx1,nx2,A=c("geology"))
print(form)

testthm <-scglrTheme(form,data=genus,H=c(2,3),family="poisson",offset = genus$surface)

Specialized screeplot (one for each theme)

screeplot(testthm)

Specialized correlation plot (one for each theme)

plot(testthm)


SCnext/SCGLR documentation built on Feb. 10, 2024, 1:44 p.m.