[R] 1-pnorm values in a table
Ben Bolker
bolker at ufl.edu
Thu Mar 6 16:47:58 CET 2008
<Richard.Cotton <at> hsl.gov.uk> writes:
[snip]
> Try:
> nrows <- 5
> mm <- matrix(rnorm(30),nrow=nrows)
> sd.by.col <- apply(mm,2,sd)
> mean.by.col <- apply(mm,2,mean)
> values <- 1-mapply(pnorm, q=as.vector(mm), mean=rep(mean.by.col, nrows)),
> sd=rep(sd.by.col, nrows)))
> values <- matrix(values, nrow=5)
>
> > p.s. I know I'm asking a lot, but ideally, I'd like to print out
> > the table with those 1-pnorm values only if they are in the right
> > hand tail (i.e. >= mean) and if not nothing or NA be written.
>
> values[values<.5] <- NA
>
I'm not sure, but I think that
nrows <- 5
mm <- matrix(rnorm(30),nrow=nrows)
pnorm(scale(mm),lower.tail=FALSE)
values[values<.5] <- NA
will do the same thing.
lower.tail=FALSE is a little more accurate than 1-pnorm(...)
cheers
Ben Bolker
More information about the R-help
mailing list