Skip to content

Commit

Permalink
fix standard errors predict + newdata
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisChau committed May 15, 2024
1 parent 593c945 commit 3df1e46
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: gslnls
Type: Package
Title: GSL Multi-Start Nonlinear Least-Squares Fitting
Version: 1.3.2
Date: 2024-04-30
Version: 1.3.3
Date: 2024-05-15
Authors@R: person("Joris", "Chau", email = "[email protected]", role = c("aut", "cre"))
Description: An R interface to nonlinear least-squares optimization with the GNU Scientific Library (GSL), see M. Galassi et al. (2009, ISBN:0954612078). The available trust region methods include the Levenberg-Marquardt algorithm with and without geodesic acceleration, the Steihaug-Toint conjugate gradient algorithm for large systems and several variants of Powell's dogleg algorithm. Multi-start optimization based on quasi-random samples is implemented using a modified version of the algorithm in Hickernell and Yuan (1997, OR Transactions). Bindings are provided to tune a number of parameters affecting the low-level aspects of the trust region algorithms. The interface mimics R's nls() function and returns model objects inheriting from the same class.
BugReports: https://github.com/JorisChau/gslnls/issues
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# gslnls 1.3.3

* Fix standard errors `predict()` when using `newdata`

# gslnls 1.3.2

* Reverted to static Makevars.win (supplied by T. Kalibera)
Expand Down
5 changes: 2 additions & 3 deletions R/nls_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,16 @@ print.gsl_nls <- function(x, digits = max(3L, getOption("digits") - 3L), ...) {
#' @export
predict.gsl_nls <- function(object, newdata, scale = NULL, interval = c("none", "confidence", "prediction"), level = 0.95, ...) {
interval <- match.arg(interval, c("none", "confidence", "prediction"))

if (missing(newdata)) {
fit <- as.vector(fitted(object))
if(interval != "none") {
Fdot <- object$m$gradient()
Rmat <- object$m$Rmat()
}
} else {
fit <- object$m$predict(newdata)
if(interval != "none") {
Fdot <- object$m$gradient1(newdata)
Rmat <- qr.R(qr(Fdot))
if(!is.null(object$weights))
warning("unweighted Jacobian matrix used to calculate standard errors, evaluate predictions without 'newdata' argument to use weighted Jacobian.")
}
Expand All @@ -291,7 +290,7 @@ predict.gsl_nls <- function(object, newdata, scale = NULL, interval = c("none",
if(is.null(scale))
scale <- sigma(object)
a <- c((1 - level) / 2, (1 + level) / 2)
ses <- scale * sqrt(1 * (interval == "prediction") + rowSums(Fdot %*% chol2inv(Rmat) * Fdot))
ses <- scale * sqrt(1 * (interval == "prediction") + rowSums(Fdot %*% chol2inv(object$m$Rmat()) * Fdot))
ci <- fit + ses %o% qt(a, df.residual(object))
cimat <- cbind(fit = fit, lwr = ci[, 1], upr = ci[, 2])
return(cimat)
Expand Down

0 comments on commit 3df1e46

Please sign in to comment.