[R-sig-Epi] Frequencies like Epiinfo

BXC (Bendix Carstensen) bxc at steno.dk
Mon Nov 29 23:55:04 CET 2010


Inside the function twoby2 from the Epi-package you will find a small locally defined function that gives you confidence intervals for proportions that are better than those you compute, which occasionally will give limits outside (0,1). 
This one is based on the logit approximation, and is what you get if you used a logistic regression to estimate the proportions:

bin.ci <- 
function(x, n) 
{
  ef <- exp(qnorm(1 - alpha/2)/sqrt(x * (n - x)/n))
  p <- x/n
  c( p, p/(p + (1 - p) * ef), p/(p + (1 - p)/ef))
}

Best regards,
Bendix Carstensen

> -----Original Message-----
> From: r-sig-epi-bounces at r-project.org 
> [mailto:r-sig-epi-bounces at r-project.org] On Behalf Of Diego Garcilazo
> Sent: 30. november 2010 08:36
> To: r-sig-epi at stat.math.ethz.ch; r-sig-epi at r-project.org
> Subject: [R-sig-Epi] Frequencies like Epiinfo
> 
> 
>  
> 
> I am trying to make a function that works like the command 
> Frequencies of Epiinfo. I am a beginner user and I make 
> something like this:
> 
>  
> 
> freq<-function(x){
> 
> Frecuencia<-table(x,exclude=NULL);
> 
> Porcentaje<-as.vector(round(prop.table(table(x,exclude=NULL)),2));
> 
> Porc<-as.vector(round(prop.table(table(x,exclude=NULL))*100,1));
> 
> Acumulado<-cumsum(Porc);
> 
> IC95.Sup<-round(as.vector(Porc+196*sqrt(Porcentaje*(1-Porcenta
je)/sum(Frecue
> ncia))),1);
> 
> IC95.Inf<-round(as.vector(Porc-196*sqrt(Porcentaje*(1-Porcenta
je)/sum(Frecue
> ncia))),1);
> 
> matrix(
> 
> c(Frecuencia,sum(Frecuencia),Porc,round(sum(Porc),1),
> 
> Acumulado,NA,IC95.Inf,NA,IC95.Sup,NA),length(Frecuencia)+1,5,
> 
> dimnames=list(c(labels(Frecuencia)[[1]],"Total"),c("Frecuencia
> ","Porcentaje"
> ,"Acumulado","[IC--","--95%]"))
> 
> );
> 
> }
> 
>  
> 
> There is a way more efficient to create a function like this?
> 
> there is a way to make it more visually - friendly adding 
> something like
> -------------- that stat.table does?
> 
> How can I add an argument like missing=T that show NA's and 
> missing=F that exclude Na's??
> 
>  
> 
> Thanks in advance. 
> 
>  
> 
> Diego. 
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Epi at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-epi
> 


More information about the R-sig-Epi mailing list