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:
You are on the right path but your function lacks a few things.
Where is the Value of Type1 coming from?
Using the approach of setting Type1 = TRUE, you would have four variables, one for each type of CI. You could use a single variable and set its value to 1,2,3, or 4.
Your calculate the value mean(x)-qnorm(1-z/2)*(sd/sqrt(n)) but you do not store that in a variable. How will you return that value from the function?
Yes that looks good except that the variables x and var are not defined. If they are defined in the environment that calls the function, the function will work, I think. I have not run the code, so there might be other problems but the general idea seems correct.