Skip to content

Commit

Permalink
binomial() $mu.eta(1L) works, too
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87553 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Jan 10, 2025
1 parent c18e5d6 commit a66024b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@
now, ditto for \code{arima0()}, thanks to \I{Norbert Kuder}'s report
on the R-devel list.

\item \code{binomial(<link>)$linkinv(eta)} now also works for
\code{"logit"} link when \code{is.integer(eta)}.
\item \code{binomial(<link>)$linkinv(eta)} and \code{.. $mu.eta(eta)}
now also work for \code{"logit"} link when \code{is.integer(eta)}.
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/library/stats/src/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,18 @@ SEXP logit_linkinv(SEXP eta)

SEXP logit_mu_eta(SEXP eta)
{
int i, n = LENGTH(eta);
if (!n || !isReal(eta))
int i, n = LENGTH(eta), nprot = 1;
if (!n || !isNumeric(eta))
error(_("Argument %s must be a nonempty numeric vector"), "eta");
if (!isReal(eta)) {eta = PROTECT(coerceVector(eta, REALSXP)); nprot++;}
SEXP ans = PROTECT(shallow_duplicate(eta));
double *rans = REAL(ans), *reta = REAL(eta);

for (i = 0; i < n; i++) {
double etai = reta[i];
double opexp = 1 + exp(etai);

rans[i] = (etai > THRESH || etai < MTHRESH) ? DBL_EPSILON :
exp(etai)/(opexp * opexp);
double etai = reta[i], expE = exp(etai), opexp = 1 + expE;
rans[i] = (etai > THRESH || etai < MTHRESH) ? DBL_EPSILON : expE/(opexp * opexp);
}
UNPROTECT(1);
UNPROTECT(nprot);
return ans;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/reg-tests-1e.R
Original file line number Diff line number Diff line change
Expand Up @@ -1722,11 +1722,14 @@ stopifnot(exprs = {
## gave solve.default() error (as wrong model failed fitting)


## binomial()$linkinv(<int>)
## binomial()$ linkinv(<int>) and binomial()$ mu.eta(<int>)
lnks <- c("logit", "probit", "cloglog", "cauchit", "log")
binIlink <- function(eta) sapply(lnks, function(lnk) binomial(lnk)$linkinv(eta))
binImuEt <- function(eta) sapply(lnks, function(lnk) binomial(lnk)$mu.eta (eta))
stopifnot(identical(binIlink( 0:3),
binIlink(as.double(0:3))))
stopifnot(identical(binImuEt( 0:3),
binImuEt(as.double(0:3))))
## integer type was not allowed for logit (only) in R <= 4.4.2


Expand Down

0 comments on commit a66024b

Please sign in to comment.