% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/internalStructure.R
\name{internalStructure}
\alias{internalStructure}
\title{Plot internal metacommunity structure}
\usage{
internalStructure(
  object,
  Rsquared = c("McFadden", "Nagelkerke"),
  fractions = c("discard", "proportional", "equal"),
  negatives = c("floor", "scale", "raw"),
  plot = FALSE
)
}
\arguments{
\item{object}{anova object from \code{\link{anova.sjSDM}}}

\item{Rsquared}{which R squared should be used, McFadden or Nagelkerke (McFadden is default)}

\item{fractions}{how to handle shared fractions}

\item{negatives}{how to handle negative R squareds}

\item{plot}{should the plots be suppressed or not.

Plots and returns the internal metacommunity structure of species and sites (see Leibold et al., 2022).
Plots were heavily inspired by Leibold et al., 2022}
}
\value{
An object of class sjSDMinternalStructure consisting of a list of data.frames with the internal structure.
}
\description{
Plot internal metacommunity structure
}
\examples{
\dontrun{
library(sjSDM)
# simulate community:
community = simulate_SDM(env = 3L, species = 10L, sites = 100L)

Occ <- community$response
Env <- community$env_weights
SP <- data.frame(matrix(rnorm(200, 0, 0.3), 100, 2)) # spatial coordinates


# fit model:
model <- sjSDM(Y = Occ, 
               env = linear(data = Env, formula = ~X1+X2+X3), 
               spatial = linear(data = SP, formula = ~0+X1*X2), 
               family=binomial("probit"),
               verbose = FALSE,
               iter = 20) # increase iter for real analysis

# Calculate ANOVA for env, space, associations, for details see ?anova.sjSDM
an = anova(model, samples = 10, verbose = FALSE) # increase iter for real analysis

# Show anova fractions
plot(an)

# ANOVA tables with different way to handle fractions
summary(an)
summary(an, fractions = "discard")
summary(an, fractions = "proportional")
summary(an, fractions = "equal")

# Internal structure
int = internalStructure(an, fractions = "proportional")

print(int)

plot(int) # default is negative values will be set to 0
plot(int, negatives = "scale") # global rescaling of all values to range 0-1
plot(int, negatives = "raw") # negative values will be discarded

plotAssemblyEffects(int)
plotAssemblyEffects(int, negatives = "floor")
plotAssemblyEffects(int, response = "sites", pred = as.factor(c(rep(1, 50), rep(2, 50))))
plotAssemblyEffects(int, response = "species", pred = runif(10))
plotAssemblyEffects(int, response = "species", pred = as.factor(c(rep(1, 5), rep(2, 5))))
}
}
\references{
Leibold, M. A., Rudolph, F. J., Blanchet, F. G., De Meester, L., Gravel, D., Hartig, F., ... & Chase, J. M. (2022). The internal structure of metacommunities. Oikos, 2022(1).
}
\seealso{
\link{plot.sjSDMinternalStructure}, \link{print.sjSDMinternalStructure}
}
