Skip to contents

This function calculates stability curves and resilience metrics based on a mixture model

Usage

# S3 method for class 'mixglm'
predict(object, newdata = NULL, samples = 1000, threshold = 0, ...)

Arguments

object

an object of class "mixglm"

newdata

dataframe of predictor values. If it contains column with response variable, obsDat is returned. If not provided, prediction is done for modelled data.

samples

number of samples to take along the response variable

threshold

number from 0 to 1 denoting how pronounced stable states should be marked as considerable

...

further arguments passed to or from other methods.

Value

A list containing the following components:

sampledResp

A numeric vector of samples along response variable

probCurves

A data frame of stability curves for each observation

tipStable

A list of data.frames for each observation with all stable states and tipping points, their scaled probability density and response variable value, whether they are stable states, and whether their satisfy the threshold

obsDat

A data frame containing values of response variable, potential energy, distance to closest tipping point and stable state for each observation, potential depth defined as a difference between potential energy of the observation and the closest tipping point

Author

Adam Klimes

Examples

if (FALSE) { # \dontrun{
set.seed(10)
n <- 200
x <- rnorm(n)
group <- rbinom(n, 1, 0.5)
y <- rnorm(n, 1 + 0.5 * x * c(-1, 1)[group + 1], 0.1)
plot(y ~ x)
dat <- data.frame(x, y)

mod <- mixglm(
  stateValModels = y ~ x,
  stateProbModels = ~ x,
  statePrecModels = ~ x,
  inputData = dat,
  numStates = 2)
predict(mod)

# predict for newdata
pre <- predict(mod, newdata = data.frame(x = c(0.5, 1), y = c(0.3, 0.2)))
plot(pre$sampledResp, pre$probCurves$X1, type = "l")
plot(pre$sampledResp, pre$probCurves$X2, type = "l")} # }