0

Suppose we have a random sample of size n = 8 from a lognormal distribution with parameters mu and sigma. Since it is a small sample, from a non-normal population I will be using the t confidence interval. I ran a simulation to determine the true (simulated) CI of a 90% t-CI in which mu=1 and sigma= 1.5

My problem is that my code below follows a NORMAL distribution and it needs to be a lognormal distribution. I know that rnorm has to become rlnorm so that the random variables come from the log distribution. But I need to change what mu and sigma are. Mu and sigma in normal distribution aren't the same in a log distribution.

Mu in the log distribution= exp(μ + 1/2 σ^2). And sigma is exp (2 (μ+sigma^2)) – exp2 (μ+sigma^2)

I'm just confused on how I can incorporate these two equations into my code.

BTW- if you didn't already guess, I am VERY new to R. Any help would be appreciated!


MC <- 10000 # Number of samples to simulate
result <- c(1:MC)
mu <- 1
sigma <- 1.5
n <- 8; # Sample size
alpha <- 0.1 # the nominal confidence level is 100(1-alpha) percent

    t_criticalValue <- qt(p=(1-alpha/2), df=(n-1))

    for(i in 1:MC){
    mySample <- rlnorm(n=n, mean=mu, sd=sigma)
    lowerCL <- mean(mySample)-t_criticalValue*sd(mySample)/sqrt(n)
    upperCL <- mean(mySample)+t_criticalValue*sd(mySample)/sqrt(n)
    result[i] <- ((lowerCL < mu) & (mu < upperCL))
    }

SimulatedConfidenceLevel <- mean(result)

EDIT: So I tried replacing mu and sd with their respective formulas...

(mu=exp(μ + 1/2 σ2) Sigma= exp(2μ + σ2)(exp(σ2) - 1)

and I got a simulatedconfidencelevel of 5000.

user3295513
  • 43
  • 1
  • 5
  • Please can you clarify what you are trying to calculate: distributions don't have confidence intervals. Are you trying to calculate a confidence interval for `mu`? Or are you trying to determine if your data came from a lognormal distribution with `mu = 1` and `sigma = 1.5`? Or something else? – Richie Cotton Feb 18 '14 at 12:35
  • yes, I'm trying to calculate the "true" or stimulated confidence interval for mu/mean – user3295513 Feb 18 '14 at 23:15

1 Answers1

0

Here's some reproducible sample data:

(x <- rlnorm(8, 1, 1.5))
## [1]  3.5415832  0.3563604  0.5052436  3.5703968  7.3696985  0.7737094 12.9768734 35.9143985

Your definition of the critical value was correct:

n <- length(x)
alpha <- 0.1 
t_critical_value <- qt(1 - alpha / 2, n - 1)

There's a utility function in the ggplot2 plotting package that calculates means and standard errors. In this case, you can apply it to the log of your data to find mu and it's confidence interval.

library(ggplot2)
mean_se(log(x), t_critical_value)    
##          y         ymin     ymax
## 1 1.088481 -0.006944755 2.183907
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360