From bolker at ufl.edu  Tue Dec  8 17:23:50 2009
From: bolker at ufl.edu (Ben Bolker)
Date: Tue, 8 Dec 2009 16:23:50 +0000 (UTC)
Subject: [Rd] lower.tail option in pnorm
References: <20091208163621.f60fi66mhw0co44o@imp.inserm.fr>
Message-ID: <loom.20091208T171116-478@post.gmane.org>

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))
.



[Rd] lower.tail option in pnorm
Ben Bolker