Skip to contents

Predictions from a stackedsdm object

Usage

# S3 method for stackedsdm
predict(
  object,
  newdata = NULL,
  type = "link",
  se.fit = FALSE,
  na.action = na.pass,
  ...
)

Arguments

object

An object of class stackedsdm

newdata

Optionally, a data frame in which to look for variables with which to predict. If omitted, the covariates from the existing dataset are used.

type

The type of prediction required. This can be supplied as either a single character string, when is applied to all species, or a vector of character strings of the same length as ncol(object$y) specifying the type of predictions desired for each species. The exact type of prediction allowed depends precisely on the distribution, but for many there is at least "link" which is on the scale of the linear predictors, and "response" which is on the scale of the response variable. The values of this argument can be abbreviated.

se.fit

Logical switch indicating if standard errors are required.

na.action

Function determining what should be done with missing values in newdata. The default is to predict NA..

...

not used

Value

A list where the k-th element is the result of applying the predict method to the k-th fitted model in object$fits.

Details

This function simply applies a for loop, cycling through each fitted model from the stackedsdm object and then attempting to construct the relevant predictions by applying the relevant predict method. Please keep in mind no formatting is done to the predictions.

Author(s)

Francis K.C. Hui <francis.hui@anu.edu.au>.

Examples

X <- spider$x
abund <- spider$abund

# Example 1: Simple example
myfamily <- "negative.binomial"
# Fit models including all covariates are linear terms, but exclude for bare sand
fit0 <- stackedsdm(abund, formula_X = ~. -bare.sand, data = X, family = myfamily, ncores=2) 
predict(fit0, type = "response")
#>        Alopacce    Alopcune    Alopfabr     Arctlute     Arctperi     Auloalbi
#> 1  18.239439075  5.72944913  1.84824965 1.733787e-01 2.614114e-01 6.246029e+00
#> 2   0.574937738 10.91758845  0.11883678 1.233708e+00 2.431815e-07 4.839317e+01
#> 3  12.796390651  8.37422532  1.22135400 4.663690e-01 4.803516e-02 1.040089e+01
#> 4   6.369090246  7.23571889  0.67265832 1.084879e+00 1.948166e-03 1.299844e+01
#> 5   1.847246864 10.66403979  0.41045498 1.489015e+00 1.764620e-05 8.287397e+00
#> 6   0.053339718  7.54439444  0.01714693 2.512629e+00 9.279045e-10 2.879000e+00
#> 7   1.790316488 12.78328159  0.25495713 6.165215e+00 1.728380e-05 9.714575e+00
#> 8   0.060496800  3.34807121  0.07847928 7.634772e-03 1.068166e-09 4.502981e+00
#> 9   4.804652178  2.38867237  0.78547053 3.629855e-01 3.940469e-02 6.398908e-02
#> 10  5.796189060  1.68662396  1.97337649 2.807266e-02 1.632348e-01 1.972793e-02
#> 11 10.674743518  2.50073273  1.61594333 1.023714e-01 2.057460e-01 3.903659e-01
#> 12 12.354251711  3.47387850  1.48946423 1.710713e-01 1.554745e-01 1.339434e+00
#> 13  1.719075301 50.81514469  0.13419156 7.425636e+00 1.733456e-04 2.015290e+01
#> 14  0.753297790  5.58325940  0.12583476 1.083397e+01 1.930809e-07 1.464170e+01
#> 15  0.023626731  7.29239238  0.02332829 1.276512e-01 2.199721e-10 8.244225e-01
#> 16  0.002244303  0.88788163  0.02450816 3.254817e-03 1.600414e-11 6.175724e-05
#> 17  0.031399335  9.82017726  0.02509812 1.558768e-01 1.041906e-09 7.693405e-01
#> 18  0.034405328  7.53034101  0.04516223 3.022311e-02 1.238446e-09 6.270717e-01
#> 19  0.005982467  1.21620548  0.02518152 9.466707e-03 3.149255e-11 3.439665e-03
#> 20  0.002112249  0.99585409  0.02105357 5.098833e-03 1.380239e-11 6.073417e-05
#> 21  0.005684769  1.61539778  0.02747983 7.436178e-03 1.792364e-11 6.111447e-03
#> 22  2.693446952  0.09773166 11.70871816 2.485391e-05 4.473446e+00 1.294083e-06
#> 23 24.195787923  0.50063982 15.31524154 1.779486e-04 8.855710e+00 5.580253e-02
#> 24 13.068803874  0.82511545  5.99586115 1.865888e-03 2.476450e+00 2.219924e-02
#> 25  3.834123624  1.20844732  3.32399352 2.604614e-03 3.131571e-04 1.484514e+00
#> 26  8.297089369  0.20577260 44.17303581 2.375144e-06 1.785605e+01 6.238258e-05
#> 27 22.962508395  0.33002954 20.61323125 5.384577e-05 2.287569e+00 1.277356e-01
#> 28 22.580750360  0.33332523 21.15718899 4.945857e-05 2.175068e+00 1.240644e-01
#>       Pardlugu    Pardmont     Pardnigr     Pardpull    Trocterr    Zoraspin
#> 1   0.14673395 46.21546509 4.571731e+00 2.286804e+01  18.3352321  1.74400341
#> 2   2.88728364  9.62564065 3.397070e+01 7.796638e+01  90.3951831 20.75715483
#> 3   0.17670987 40.47461115 1.104517e+01 4.515780e+01  32.3616070  3.56653846
#> 4   0.32927856 41.79161499 2.031875e+01 7.041935e+01  43.8164845  7.68985486
#> 5   0.93614429  9.07087888 9.866695e+01 4.405246e+01 138.7180969 28.55463853
#> 6   3.32587128  7.04213262 9.804684e+00 1.237658e+01  57.6057630 15.77690371
#> 7   0.56385795 18.66309570 1.234824e+02 1.007958e+02 148.8111236 36.27503647
#> 8  26.25187948  0.78179195 1.340972e+00 7.890039e-01  22.9857922  3.11312349
#> 9   0.06793954 49.95754379 2.081384e+00 1.986247e+00  11.2139988  1.43401223
#> 10  0.09422697 15.72709170 9.316283e-01 2.757519e-01   7.9268024  0.63335099
#> 11  0.10576271 47.14012274 1.600086e+00 3.460346e+00   9.3564798  0.97926407
#> 12  0.12270998 53.86315317 2.670330e+00 9.188397e+00  12.6292245  1.39331046
#> 13  0.17807669 16.04219884 4.142190e+01 1.234677e+02 130.8191121 11.06876236
#> 14  1.81532567 30.15026027 1.389557e+02 1.634871e+02 126.6461033 73.16976425
#> 15  8.61005347  0.85836505 3.892906e+00 9.310314e-01  51.0227314  7.19512558
#> 16  8.36622883  0.07483028 3.066005e-01 3.975826e-04  14.6242186  1.58643682
#> 17  4.93906712  0.96911828 3.524352e+00 1.011545e+00  50.8350811  5.63734903
#> 18  8.65363817  0.45495797 2.639564e+00 3.944188e-01  44.8805177  4.20044127
#> 19 11.89787290  0.29309531 5.059937e-01 9.006105e-03  15.4748074  2.36951595
#> 20  7.29219102  0.08257814 3.682140e-01 4.854220e-04  16.3574371  1.83033895
#> 21 16.82592849  0.17765208 7.813532e-01 1.033129e-02  21.9123589  3.03423657
#> 22  0.06920151  1.46477591 9.372339e-03 2.979863e-05   0.6045805  0.02023397
#> 23  0.29363456  9.45280688 8.838901e-02 5.688250e-02   1.7354742  0.08741095
#> 24  0.13388839 13.45905784 2.083026e-01 9.380578e-02   3.0348509  0.18053844
#> 25  3.61200153  3.28647894 3.463452e+00 9.000806e-01  16.5802466  2.36683229
#> 26  0.27056389  0.42166194 1.940265e-02 9.175248e-05   1.0923949  0.02147195
#> 27  0.83371593  6.61331698 7.766916e-02 5.116620e-02   1.5198742  0.09073516
#> 28  0.86658930  6.06029510 7.947422e-02 4.773396e-02   1.5598137  0.09142142

# \donttest{
# Example 2: Funkier example where Species are assumed to have different distributions
abund[,1:3] <- (abund[,1:3]>0)*1 # First three columns for presence absence
myfamily <- c(rep(c("binomial"), 3),
       rep(c("negative.binomial"), 5),
       rep(c("tweedie"), 4)
       )
fit0 <- stackedsdm(abund, formula_X = ~ bare.sand, data = X, family = myfamily, ncores=2)
predict(fit0, type = "response")
#>     Alopacce   Alopcune  Alopfabr  Arctlute    Arctperi  Auloalbi  Pardlugu
#> 1  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 2  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 3  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 4  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 5  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 6  0.8635980 0.43106837 0.8265953 0.5916564  0.88208574 1.7510773 0.7451292
#> 7  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 8  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 9  0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 10 0.9602934 0.13499534 0.9801575 0.3729749  9.05551052 0.7160559 0.1821669
#> 11 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 12 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 13 0.7885040 0.58584687 0.6542511 0.7099879  0.35145427 2.4932161 1.3000532
#> 14 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 15 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 16 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 17 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 18 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 19 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 20 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 21 0.4379158 0.89957172 0.1097251 1.2171196  0.02314281 7.0862156 6.7387742
#> 22 0.9306739 0.23802342 0.9464921 0.4567645  3.25610041 1.0605149 0.3381893
#> 23 0.9176213 0.28018845 0.9273941 0.4870765  2.35427463 1.2011487 0.4114807
#> 24 0.9306739 0.23802342 0.9464921 0.4567645  3.25610041 1.0605149 0.3381893
#> 25 0.9469193 0.18261553 0.9667202 0.4141730  5.33648900 0.8772650 0.2508310
#> 26 0.9756768 0.07914657 0.9916957 0.3133469 21.81483980 0.5108911 0.1070307
#> 27 0.8635980 0.43106837 0.8265953 0.5916564  0.88208574 1.7510773 0.7451292
#> 28 0.9399572 0.20673274 0.9585553 0.4332241  4.25285269 0.9571539 0.2877438
#>     Pardmont  Pardnigr  Pardpull  Trocterr Zoraspin
#> 1  20.240920 20.390416 31.073385 48.705683 7.911132
#> 2  20.240920 20.390416 31.073385 48.705683 7.911132
#> 3  20.240920 20.390416 31.073385 48.705683 7.911132
#> 4  20.240920 20.390416 31.073385 48.705683 7.911132
#> 5  20.240920 20.390416 31.073385 48.705683 7.911132
#> 6  10.255083  6.458673  6.290503 15.154373 4.954795
#> 7  20.240920 20.390416 31.073385 48.705683 7.911132
#> 8  20.240920 20.390416 31.073385 48.705683 7.911132
#> 9  20.240920 20.390416 31.073385 48.705683 7.911132
#> 10  6.638133  3.095706  2.264300  7.181103 3.673106
#> 11 20.240920 20.390416 31.073385 48.705683 7.911132
#> 12 20.240920 20.390416 31.073385 48.705683 7.911132
#> 13 12.178051  8.636612  9.419498 20.356319 5.576868
#> 14 20.240920 20.390416 31.073385 48.705683 7.911132
#> 15 20.240920 20.390416 31.073385 48.705683 7.911132
#> 16 20.240920 20.390416 31.073385 48.705683 7.911132
#> 17 20.240920 20.390416 31.073385 48.705683 7.911132
#> 18 20.240920 20.390416 31.073385 48.705683 7.911132
#> 19 20.240920 20.390416 31.073385 48.705683 7.911132
#> 20 20.240920 20.390416 31.073385 48.705683 7.911132
#> 21 20.240920 20.390416 31.073385 48.705683 7.911132
#> 22  8.035432  4.275976  3.546768  9.968886 4.189161
#> 23  8.537155  4.737076  4.089088 11.061470 4.367459
#> 24  8.035432  4.275976  3.546768  9.968886 4.189161
#> 25  7.327193  3.658319  2.855590  8.508245 3.931430
#> 26  5.632903  2.345208  1.539581  5.416753 3.280628
#> 27 10.255083  6.458673  6.290503 15.154373 4.954795
#> 28  7.644479  3.930157  3.154610  9.150654 4.047810
# }