Hey guys, I have to write a function that is able to calculate all four types of confidence interval (of an average). The function should include the parameter "case/type", with that the user can state for which type the confidence interval should be calculated.
I´ve got the idea that I have to define the four types first and name them accordingly and then I have to work with "if". But I don´t know what I am supposed to pack into the function. Is there someone who might help me?
Edit: I have specified four types of CI:
- normally distributed, variance known
- normally distributed, variance unknown
- arbitrarily distributed, variance known, n>30
- arbitrarily distributed, variance unknown, n>30
Now I guess I have to start with the function like this:
CI<-function(n,mean,sd,z){
if(Type1==TRUE){
mean(x)-qnorm(1-z/2)*(sd/sqrt(n))
mean(x)+qnorm(1-z/2)*(sd/sqrt(n))}
if(Type2==TRUE){
}}
AND SO ON
Can I do it like that or have I used "if" or any other part of this function in a wrong way?
Best regards!
Thanks in advance,
klaus