-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error for predict along a gradient with NNGP #96
Comments
I can reproduce this in an NNGP model. I'll have a look at this. |
This is now fixed in commit ee1367a. Please try the githbut version of Hmsc to see if it cures your problem (sloppy coding). |
thanks! I tried it with the updated version and the original error seems to be fixed. However I now get and error saying
also, weirdly, when testing the same code on another model that is identical to the model m1 in all but that it uses abundance data conditional on presence (the second part of the hurdle model) the original error still occurs. |
This error does not come directly from Hmsc, but from some other package or R function that we use. After getting the error, write |
this is what I get
|
This error message could appear if you have (almost) identical spatial coordinates – check if this is the case.
Otso
From: FabianRoger ***@***.***>
Sent: torstai 29. huhtikuuta 2021 23:53
To: hmsc-r/HMSC ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [hmsc-r/HMSC] error for predict along a gradient with NNGP (#96)
this is what I get
traceback()
9: h(simpleError(msg, call))
8: .handleSimpleError(function (cond)
.Internal(C_tryCatchHelper(addr, 1L, cond)), "the leading minor of order 1 is not positive definite",
base::quote(chol.default(W)))
7: chol.default(W)
6: chol(W)
5: t(chol(W))
4: predictLatentFactor(unitsPred = levels(dfPiNew[, r]), units = levels(object$dfPi[,
r]), postEta = postEta, postAlpha = postAlpha, rL = rL[[r]],
predictMean = predictEtaMean, predictMeanField = predictEtaMeanField)
3: predict.Hmsc(models$m1, Gradient = Gradient, expected = TRUE)
2: predict(models$m1, Gradient = Gradient, expected = TRUE)
1: predict(models$m1, Gradient = Gradient, expected = TRUE)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#96 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEIYMZQJXVIC2FV46YM754TTLHBK5ANCNFSM43ZTTQHA>.
|
What bugs me in this error is that you should never execute command |
For anybody trying to inspect the issue, here is how I generated the reproducible test case: m <- TD$m
rL1 <- TD$rL1
rL1 <- update(rL1, sMethod="NNGP", nNeighbours=4)
m <- update(m, ranLevels = list(sample = TD$rL2, plot = rL1))
m <- sampleMcmc(m, samples=100, thin=1, transient=50, nChains=2, nParallel=2)
Gradient <- constructGradient(m, focalVariable = "x2")
predY <- predict(m, Gradient = Gradient, expected = TRUE) # fails before ee1367a Can you use something similar to reproduce your problem? |
re distance between points: It shouldn't be, no. The coordinates are centroids and about 20 km apart form each other. I checked and the minimum distance between any two points is 26km. |
weirdly enough the repex above runs without error for me. |
Are there any updates about this issue? traceback() |
I am also getting this error for a non-spatial model, although I have a temporal effect of year. I am just trying to create the gradient plots by covariate, not make spatial predictions - those are working fine.
m = Hmsc(Y = Y, XData = X, XFormula = XFormula.1.d, Gradient_cov = constructGradient(m, focalVariable = "rugosity") traceback() |
I have been having the same error with my temporal random effect. I cannot make prediction if I define it with argument
|
@Yo-B This is one of the issues I have been studying recently: thank you for supplying a reproducible example. I have an experimental, dirty and noisy fix for this discussed in issue #123. You can try this installing the experimental branch with command The reason of failure in several of these cases seems to be that Gradient values duplicate data and therefore you have zero-distances between Gradient points and data points (training points). This in turn gives you zero W matrix – and a matrix of zeros is not positive definite. The purpose of this calculation is to get the value of standard error for random normal variate, and that standard error is distance-dependent, and zero when distance is zero. The risk of duplicating data points is particularly large in time random variables which – like in your case – are integer years and the generated Gradient values will duplicate data values. This fix may also work with the cases of @cgoetsch, @fkeppeler and @FabianRoger but I haven't tested with their data. Remember: you should get a lot of error messages, but these will not stop the analysis, but you will get a result. |
I fitted a model with a spatial random factor with the 'NNGP' method. Now I tried to predict with this model along a gradient.
My code is
This gives me the error
Googling the error message brings me here but I am not sure if this is what's going on internally. If necessary, I can try to provide a repex later.
Thanks!
The text was updated successfully, but these errors were encountered: