# Re: [R] Computing normal conf.intervals

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Thu, 20 Dec 2007 12:34:44 +0100

Jonas Malmros wrote:
> Hi everybody,
>
> I wonder if there is a built-in function similar to Matlab's "normfit"
> which computes 95% CI based on the normality assumption.
> So, I have a vector of values and I want to calculate 95% normal CI.
> Of course, I could write my own function, no problem, but I still
> wonder if built-in functionality exists. (I wish quantile() had this
> functionality included).
> Anyone knows?
>
>

First, be more clear about what the intention is. Prediction intervals, or confidence intervals for the mean? If the former, do you want the crude version (plus/minus 1.96s) or the version that takes the estimation variance into account

> x <- rnorm(10)
> qnorm(c(.025,.975), mean=mean(x), sd=sd(x))
 -1.763791 1.465144
> predict(lm(x~1), newdata=data.frame(1), interval="p")

fit lwr upr
[1,] -0.1493235 -2.103664 1.805017
> confint(lm(x~1))

```                 2.5 %    97.5 %
```

(Intercept) -0.7385793 0.4399324

> Also, I wonder if there is a function similar to Matlab's "flipud".
> Obviously there is package "matlab" which has this function, but I
> wonder if I can turn a matrix upside-down without loading matlab
> package.
>
>

M[nrow(M):1,]

or (safer if nrow==0)

M[rev(seq_len(nrow(M))),]

>
> Best,
> JM
>
>
>

```--
O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help