Reputation: 423
I have two questions:
First,I a qualitative variable Type class(Type)=table
with different frequencies of categories, say
Type
Type1 Type2 Type3
150 4900 4
and a statistic for each of the categories I calculated before in another function (class is data frame) :
df
Var1 Freq
1 Type1 0.1800
2 Type2 0.1130
3 Type3 0.2500
I want to calculate the confidence interval for each category automatically in a function that returns two vectors of the upper and lower bounds of the confidence intervalls. The formula for the confidence interval would be:
df[1, 2] + 1.96*sqrt(df[1, 2]*(1 - df[1, 2])/t[[1]])
so that the function extract the corresponding values from the table and the dataframe.
Do I have to use for loop like this?
ci <- function(stat, Type){
p <- tapply(stat, Type, function(x) sum(x)/length(x))
df <- as.data.frame(as.table(p))
t <- table(Type)
for (i in nrow(df)) {
for (j in t)
}
}
Upvotes: 0
Views: 825
Reputation:
summarySE
is function in the package Rmisc
. By this function you can calculate CI for different categories. Current version 1.5 is available for R 3.4.0
Upvotes: 0