#USAGE: CI_normal(matrix[,c(x:y)],97.5) - multiple column from a normal distribution
#USAGE: CI_tdist(matrix[,c(x:y)],97.5) - multiple column from a t distribution
#USAGE: CI_normal(matrix[,x],97.5) - single column from a normal distribution
#USAGE: CI_tdist(matrix[,x],97.5) - single column from a t distribution
#Created and updated by Santhilal Subhash on 2016/06/07
CI_normal <- function(li,stat)
{
cat(paste0("CI","\t","column","\t","Lower.limit","\t","Upper.limit","\n"))
if(length(colnames(li))>1)
{
for(i in 1:length(colnames(li)))
{
sample <- colnames(li)
error <- qnorm(stat/100)*sd(li[,i])/sqrt(length(li[,i]))
left <- mean(li[,i])-error
right <- mean(li[,i])+error
cat(paste0(stat,"% norm dist","\t",sample[i],"\t",left,"\t",right,"\n"))
}
}
else{
error <- qnorm(stat/100)*sd(li)/sqrt(length(li))
left <- mean(li)-error
right <- mean(li)+error
cat(paste0(stat,"% norm dist","\tNA","\t",left,"\t",right,"\n"))
}
}
CI_tdist <- function(li,stat)
{
cat(paste0("CI","\t","column","\t","Lower.limit","\t","Upper.limit","\n"))
if(length(colnames(li))>1)
{
for(i in 1:length(colnames(li)))
{
sample <- colnames(li)
error <- qt(stat/100,df=length(li[,i])-1)*sd(li[,i])/sqrt(length(li[,i]))
left <- mean(li[,i])-error
right <- mean(li[,i])+error
cat(paste0(stat,"% t-dist","\t",sample[i],"\t",left,"\t",right,"\n"))
}
}
else{
error <- qt(stat/100,df=length(li)-1)*sd(li)/sqrt(length(li))
left <- mean(li)-error
right <- mean(li)+error
cat(paste0(stat,"% t-dist","\tNA","\t",left,"\t",right,"\n"))
}
}