Re: [Rd] lower.tail option in pnorm

From: Ben Bolker <bolker_at_ufl.edu>
Date: Tue, 08 Dec 2009 16:23:50 +0000 (UTC)

Ken Knoblauch <ken.knoblauch <at> inserm.fr> writes:

>
> Hi,
>
> I would have thought that these two constructions would
> produce the same result but they do not.
>
> Resp <- rbinom(10, 1, 0.5)
> Stim <- rep(0:1, 5)
> mm <- model.matrix(~ Stim)
> Xb <- mm %*% c(0, 1)
> ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb)))
> pnorm(as.vector(Xb), lower.tail = Resp, log.p = TRUE)
>

  [snip]

> If I have missed something obvious, I would be grateful
> to have it pointed out.
>

 lower.tail is not vectorized. All elements but the first are ignored. This seems fairly obvious to me from reading ?pnorm (e.g. "mean" is described a "vector of means", "sd" is described as "vector of standard deviations", but lower.tail is described as "logical", but 'obvious' is certainly in the eye of the beholder.

You can do what you want with

mapply(pnorm,q=c(-1,1),lower.tail=c(0,1)) .



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 08 Dec 2009 - 16:28:10 GMT

This archive was generated by hypermail 2.2.0 : Tue 08 Dec 2009 - 16:31:01 GMT