predictqrrvglm.RdPredicted values based on a constrained quadratic ordination (CQO) object.
predictqrrvglm(object, newdata = NULL,
type = c("link", "response", "latvar", "terms"),
se.fit = FALSE, deriv = 0, dispersion = NULL,
extra = object@extra, varI.latvar = FALSE, refResponse = NULL, ...)Object of class inheriting from "qrrvglm".
An optional data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used.
See predictvglm.
Derivative. Currently only 0 is handled.
Arguments passed into Coef.qrrvglm.
Currently undocumented.
Obtains predictions from a fitted CQO object. Currently there are lots of limitations of this function; it is unfinished.
See predictvglm.
Yee, T. W. (2004). A new technique for maximum-likelihood canonical Gaussian ordination. Ecological Monographs, 74, 685–701.
This function is not robust and has not been checked fully.
if (FALSE) set.seed(1234)
hspider[, 1:6] <- scale(hspider[, 1:6]) # Standardize the X vars
p1 <- cqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute,
Arctperi, Auloalbi, Pardlugu, Pardmont,
Pardnigr, Pardpull, Trocterr, Zoraspin) ~
WaterCon + BareSand + FallTwig + CoveMoss + CoveHerb + ReflLux,
poissonff, data = hspider, Crow1positive = FALSE, I.toler = TRUE)
#>
#> ========================= Fitting model 1 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.7249
#> BareSand 0.1070
#> FallTwig 0.0221
#> CoveMoss 0.1329
#> CoveHerb -0.4850
#> ReflLux 1.2719
#>
#> Using BFGS algorithm
#> initial value 3224.649028
#> Taking evasive action for latent variable 1.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 7. Trying internal starting values.
#> cqo_1; no convergence for Species number 7. Continuing on with other species.
#> cqo_1; no convergence for Species number 8. Trying internal starting values.
#> cqo_1; no convergence for Species number 8. Continuing on with other species.
#> cqo_1; no convergence for Species number 9. Trying internal starting values.
#> cqo_1; no convergence for Species number 9. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> cqo_1; no convergence for Species number 12. Trying internal starting values.
#> cqo_1; no convergence for Species number 12. Continuing on with other species.
#> iter 10 value 1758.557269
#> iter 20 value 1635.585417
#> iter 30 value 1599.137902
#> iter 40 value 1590.285046
#> iter 50 value 1586.943302
#> iter 60 value 1585.519688
#> final value 1585.124207
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.124
#> Parameters (= c(C)) =
#> -0.3554454 0.5534211 -0.9226307 0.317293 -0.3046504 0.6999011
#>
#> Number of function evaluations = 69
#>
#>
#> ========================= Fitting model 2 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.651
#> BareSand 0.248
#> FallTwig 0.131
#> CoveMoss 0.307
#> CoveHerb -0.644
#> ReflLux 1.120
#>
#> Using BFGS algorithm
#> initial value 3922.478237
#> iter 10 value 3856.868079
#> iter 20 value 3756.910877
#> iter 30 value 3621.079452
#> iter 40 value 3448.891289
#> iter 50 value 3250.093001
#> Taking evasive action for latent variable 1.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 4. Trying internal starting values.
#> cqo_1; no convergence for Species number 4. Continuing on with other species.
#> cqo_1; no convergence for Species number 6. Trying internal starting values.
#> cqo_1; no convergence for Species number 6. Continuing on with other species.
#> cqo_1; no convergence for Species number 7. Trying internal starting values.
#> cqo_1; no convergence for Species number 7. Continuing on with other species.
#> cqo_1; no convergence for Species number 8. Trying internal starting values.
#> cqo_1; no convergence for Species number 8. Continuing on with other species.
#> cqo_1; no convergence for Species number 9. Trying internal starting values.
#> cqo_1; no convergence for Species number 9. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> cqo_1; no convergence for Species number 12. Trying internal starting values.
#> cqo_1; no convergence for Species number 12. Continuing on with other species.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> iter 60 value 1915.024539
#> iter 70 value 1654.573401
#> iter 80 value 1625.255269
#> iter 90 value 1599.620908
#> iter 100 value 1591.583450
#> iter 110 value 1585.731327
#> iter 120 value 1585.283013
#> iter 130 value 1585.188116
#> final value 1585.122269
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.122
#> Parameters (= c(C)) =
#> -0.357794 0.5532135 -0.9174005 0.3157608 -0.3059107 0.7071997
#>
#> Number of function evaluations = 143
#>
#>
#> ========================= Fitting model 3 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.227
#> BareSand 0.778
#> FallTwig -0.735
#> CoveMoss 0.243
#> CoveHerb -0.546
#> ReflLux 0.445
#>
#> Using BFGS algorithm
#> initial value 2483.282038
#> iter 10 value 1614.788540
#> iter 20 value 1589.617189
#> iter 30 value 1587.375930
#> iter 40 value 1585.521022
#> iter 50 value 1585.189361
#> iter 60 value 1585.149922
#> final value 1585.147392
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.147
#> Parameters (= c(C)) =
#> -0.3568523 0.5533839 -0.9267132 0.3177334 -0.3053544 0.6957577
#>
#> Number of function evaluations = 88
#>
#>
#> ========================= Fitting model 4 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.372
#> BareSand 0.284
#> FallTwig -0.898
#> CoveMoss 0.242
#> CoveHerb -0.371
#> ReflLux 0.589
#>
#> Using BFGS algorithm
#> initial value 1827.630047
#> iter 10 value 1592.395584
#> iter 20 value 1587.188315
#> iter 30 value 1585.627648
#> iter 40 value 1585.371453
#> iter 50 value 1585.268789
#> final value 1585.153144
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.153
#> Parameters (= c(C)) =
#> -0.3552584 0.5538153 -0.9277198 0.3186391 -0.3058492 0.6945514
#>
#> Number of function evaluations = 73
#>
#>
#> ========================= Fitting model 5 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.0476
#> BareSand 0.5259
#> FallTwig -0.6460
#> CoveMoss 0.3976
#> CoveHerb -0.3554
#> ReflLux 0.7980
#>
#> Using BFGS algorithm
#> initial value 1863.907879
#> iter 10 value 1609.806705
#> iter 20 value 1588.110570
#> iter 30 value 1586.079944
#> iter 40 value 1585.370725
#> iter 50 value 1585.212809
#> final value 1585.117909
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.118
#> Parameters (= c(C)) =
#> -0.3564608 0.5533059 -0.9171126 0.3161661 -0.3053415 0.7068372
#>
#> Number of function evaluations = 69
#>
#>
#> ========================= Fitting model 6 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.3279
#> BareSand 1.1155
#> FallTwig -0.7549
#> CoveMoss 0.0164
#> CoveHerb 0.1442
#> ReflLux 0.1422
#>
#> Using BFGS algorithm
#> initial value 2644.692787
#> iter 10 value 2604.779427
#> iter 20 value 2558.623425
#> iter 30 value 2510.937888
#> iter 40 value 2462.273952
#> Taking evasive action for latent variable 1.
#> cqo_1; no convergence for Species number 1. Trying internal starting values.
#> cqo_1; no convergence for Species number 1. Continuing on with other species.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 3. Trying internal starting values.
#> cqo_1; no convergence for Species number 3. Continuing on with other species.
#> cqo_1; no convergence for Species number 7. Trying internal starting values.
#> cqo_1; no convergence for Species number 7. Continuing on with other species.
#> cqo_1; no convergence for Species number 8. Trying internal starting values.
#> cqo_1; no convergence for Species number 8. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> Taking evasive action for latent variable 1.
#> cqo_1; no convergence for Species number 1. Trying internal starting values.
#> cqo_1; no convergence for Species number 1. Continuing on with other species.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 3. Trying internal starting values.
#> cqo_1; no convergence for Species number 3. Continuing on with other species.
#> cqo_1; no convergence for Species number 7. Trying internal starting values.
#> cqo_1; no convergence for Species number 7. Continuing on with other species.
#> cqo_1; no convergence for Species number 8. Trying internal starting values.
#> cqo_1; no convergence for Species number 8. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> iter 50 value 1838.760457
#> iter 60 value 1649.024047
#> iter 70 value 1627.596694
#> iter 80 value 1594.614592
#> iter 90 value 1588.036677
#> iter 100 value 1585.850516
#> iter 110 value 1585.378521
#> iter 120 value 1585.151361
#> final value 1585.141229
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.141
#> Parameters (= c(C)) =
#> -0.356567 0.5540018 -0.9257672 0.3176971 -0.3051099 0.6962166
#>
#> Number of function evaluations = 162
#>
#>
#> ========================= Fitting model 7 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.294
#> BareSand 0.339
#> FallTwig -0.582
#> CoveMoss 0.509
#> CoveHerb -0.438
#> ReflLux 0.670
#>
#> Using BFGS algorithm
#> initial value 2138.178175
#> iter 10 value 1592.915943
#> iter 20 value 1586.504245
#> iter 30 value 1585.775765
#> iter 40 value 1585.240673
#> iter 50 value 1585.148000
#> final value 1585.116023
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.116
#> Parameters (= c(C)) =
#> -0.3562152 0.5540555 -0.9192856 0.3166152 -0.3043092 0.7036506
#>
#> Number of function evaluations = 57
#>
#>
#> ========================= Fitting model 8 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.230
#> BareSand 0.924
#> FallTwig -0.311
#> CoveMoss 0.426
#> CoveHerb -0.472
#> ReflLux 0.490
#>
#> Using BFGS algorithm
#> initial value 3192.593977
#> iter 10 value 3022.244439
#> Taking evasive action for latent variable 1.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 4. Trying internal starting values.
#> cqo_1; no convergence for Species number 4. Continuing on with other species.
#> cqo_1; no convergence for Species number 7. Trying internal starting values.
#> cqo_1; no convergence for Species number 7. Continuing on with other species.
#> cqo_1; no convergence for Species number 8. Trying internal starting values.
#> cqo_1; no convergence for Species number 8. Continuing on with other species.
#> cqo_1; no convergence for Species number 9. Trying internal starting values.
#> cqo_1; no convergence for Species number 9. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> cqo_1; no convergence for Species number 12. Trying internal starting values.
#> cqo_1; no convergence for Species number 12. Continuing on with other species.
#> iter 20 value 1641.833928
#> iter 30 value 1590.860516
#> iter 40 value 1586.362221
#> iter 50 value 1585.140198
#> final value 1585.122089
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.122
#> Parameters (= c(C)) =
#> -0.3573081 0.5529374 -0.9204031 0.3158835 -0.3056007 0.7035435
#>
#> Number of function evaluations = 60
#>
#>
#> ========================= Fitting model 9 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.1092
#> BareSand 1.0517
#> FallTwig -1.0779
#> CoveMoss 0.0881
#> CoveHerb -0.1848
#> ReflLux 0.1055
#>
#> Using BFGS algorithm
#> initial value 2431.004175
#> Taking evasive action for latent variable 1.
#> cqo_1; no convergence for Species number 2. Trying internal starting values.
#> cqo_1; no convergence for Species number 2. Continuing on with other species.
#> cqo_1; no convergence for Species number 3. Trying internal starting values.
#> cqo_1; no convergence for Species number 3. Continuing on with other species.
#> cqo_1; no convergence for Species number 7. Trying internal starting values.
#> cqo_1; no convergence for Species number 7. Continuing on with other species.
#> cqo_1; no convergence for Species number 8. Trying internal starting values.
#> cqo_1; no convergence for Species number 8. Continuing on with other species.
#> cqo_1; no convergence for Species number 11. Trying internal starting values.
#> cqo_1; no convergence for Species number 11. Continuing on with other species.
#> iter 10 value 1670.398238
#> iter 20 value 1632.155056
#> iter 30 value 1615.230988
#> iter 40 value 1593.468679
#> iter 50 value 1588.077394
#> iter 60 value 1585.517739
#> iter 70 value 1585.330155
#> iter 80 value 1585.188510
#> iter 90 value 1585.143642
#> final value 1585.135345
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.135
#> Parameters (= c(C)) =
#> -0.3560228 0.5529195 -0.9249546 0.3177938 -0.3051559 0.6974912
#>
#> Number of function evaluations = 95
#>
#>
#> ========================= Fitting model 10 =========================
#>
#> Obtaining initial values
#>
#> Using initial values
#> latvar
#> WaterCon -0.224
#> BareSand 0.306
#> FallTwig -0.406
#> CoveMoss 0.551
#> CoveHerb -0.244
#> ReflLux 0.872
#>
#> Using BFGS algorithm
#> initial value 2027.370886
#> iter 10 value 1632.245505
#> iter 20 value 1600.891868
#> iter 30 value 1589.303689
#> iter 40 value 1588.125933
#> iter 50 value 1586.025468
#> iter 60 value 1585.310511
#> iter 70 value 1585.142137
#> iter 80 value 1585.124130
#> final value 1585.120817
#> converged
#>
#> BFGS using optim():
#> Objective = 1585.121
#> Parameters (= c(C)) =
#> -0.357089 0.5537124 -0.9184166 0.3153578 -0.3057808 0.7060572
#>
#> Number of function evaluations = 83
#>
sort(deviance(p1, history = TRUE)) # A history of all the iterations
#> [1] 1585.116 1585.118 1585.121 1585.122 1585.122 1585.124 1585.135 1585.141
#> [9] 1585.147 1585.153
head(predict(p1))
#> loglink(E[Alopacce]) loglink(E[Alopcune]) loglink(E[Alopfabr])
#> [1,] 2.5596358 1.937937 0.3120846
#> [2,] -3.5160072 2.223508 -8.6852134
#> [3,] 2.1085231 2.401033 -0.5589171
#> [4,] 1.5246898 2.719058 -1.5569667
#> [5,] -0.6815543 2.895922 -4.8577531
#> [6,] -3.2494126 2.309846 -8.3358285
#> loglink(E[Arctlute]) loglink(E[Arctperi]) loglink(E[Auloalbi])
#> [1,] -0.2605387 -4.444446 1.447622
#> [2,] 0.7588673 -17.986716 2.314340
#> [3,] 0.3080216 -5.968633 1.994239
#> [4,] 0.7300858 -7.611044 2.394655
#> [5,] 1.1818664 -12.614518 2.789234
#> [6,] 0.8244111 -17.508541 2.384211
#> loglink(E[Pardlugu]) loglink(E[Pardmont]) loglink(E[Pardnigr])
#> [1,] -3.6461288 3.9761855 2.709904
#> [2,] 2.1653881 0.7701914 3.376639
#> [3,] -2.3888649 3.9374876 3.227780
#> [4,] -1.2874012 3.7604976 3.599844
#> [5,] 0.9596522 2.6293127 3.919503
#> [6,] 2.0951389 0.9554694 3.452176
#> loglink(E[Pardpull]) loglink(E[Trocterr]) loglink(E[Zoraspin])
#> [1,] 3.334081 3.144273 1.452498
#> [2,] 3.531266 4.477943 2.833399
#> [3,] 3.784475 3.757998 2.073011
#> [4,] 4.089969 4.224617 2.546326
#> [5,] 4.233720 4.794131 3.133534
#> [6,] 3.620109 4.534582 2.888699
# The following should be all 0s:
max(abs(predict(p1, newdata = head(hspider)) - head(predict(p1))))
#> [1] 2.842171e-13
max(abs(predict(p1, newdata = head(hspider), type = "res")-head(fitted(p1))))
#> [1] 1.136868e-13
# \dontrun{}