Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with eric_kernfeld's answer chosen by CommunityBot
added 69 characters in body
Source Link
Nick
  • 856
  • 7
  • 25

Edit 3.

library(Johnson)
  
set.seed(1)
n <- 252
log_mydata1 <- runif(n, min=-0.06, max= 0.05)

# Applying SU Johnson transformation

jt_mydata1<-RE.Johnson(log_mydata1)
z1 <- jt_mydata1$transformed; shapiro.test(z1) # W = 0.99495, p-value = 0.5748

mean(z1); sd(z1) # -0.02276707,  1.002103

# fpar1  <- ArimaModelFit(z1)
# Coefficients:
#         ar1     ar2      ar3      ma1      ma2  intercept
#      0.5520  0.4231  -0.1234  -0.5468  -0.4532    -0.0302
# s.e.  0.3582  0.3492   0.0666   0.3572   0.3570     0.0075


#ARMA  Simulation
sim1 <- arima.sim(list(order = c(3,0,2), 
                          ar = c(0.5520,  0.4231,  -0.1234), 
                          ma = c(-0.5468,  -0.4532)), n = n)

mean(sim1);sd(sim1) #  -0.0350542, 1.041598
shapiro.test(sim1)  # W = 0.99285, p-value = 0.2675

# convert an normalized variable back to a marginal variable    
gamma1   <- jt_mydata1$f.gamma
lambda1  <- jt_mydata1$f.lambda
epsilon1 <- jt_mydata1$f.epsilon
eta1     <- jt_mydata1$f.eta
# SU
# inv_jt_mydata1 <- lambda1 * sinh((sim1 - gamma1)/eta1) +  epsilon1
mean(# SB
inv_jt_mydata1 <- ((lambda1 + epsilon1);sd* exp(inv_jt_mydata1(sim1 - gamma1)
#[1]/eta1) +  epsilon1)/(1+exp((sim1 -0.09473195
#[1] 0.4666171gamma1)/eta1))

The p-value of Kolmogorov-Smirnov test is less 2.2e-16 and$0.97$

ks.test(log_mydata1, inv_jt_mydata1)
#    D = 0.53571043651, p-value <= 20.2e-1697
# alternative hypothesis: two-sided

and CDFs are differentclose each to other: enter image description here

enter image description here

library(Johnson)

set.seed(1)
n <- 252
log_mydata1 <- runif(n, min=-0.06, max= 0.05)

# Applying SU Johnson transformation

jt_mydata1<-RE.Johnson(log_mydata1)
z1 <- jt_mydata1$transformed; shapiro.test(z1) # W = 0.99495, p-value = 0.5748

mean(z1); sd(z1) # -0.02276707,  1.002103

# fpar1  <- ArimaModelFit(z1)
# Coefficients:
#         ar1     ar2      ar3      ma1      ma2  intercept
#      0.5520  0.4231  -0.1234  -0.5468  -0.4532    -0.0302
# s.e.  0.3582  0.3492   0.0666   0.3572   0.3570     0.0075


#ARMA  Simulation
sim1 <- arima.sim(list(order = c(3,0,2), 
                          ar = c(0.5520,  0.4231,  -0.1234), 
                          ma = c(-0.5468,  -0.4532)), n = n)

mean(sim1);sd(sim1) #  -0.0350542, 1.041598
shapiro.test(sim1)  # W = 0.99285, p-value = 0.2675

# convert an normalized variable back to a marginal variable    
gamma1   <- jt_mydata1$f.gamma
lambda1  <- jt_mydata1$f.lambda
epsilon1 <- jt_mydata1$f.epsilon
eta1     <- jt_mydata1$f.eta

inv_jt_mydata1 <- lambda1 * sinh((sim1 - gamma1)/eta1) +  epsilon1
mean(inv_jt_mydata1);sd(inv_jt_mydata1)
#[1] -0.09473195
#[1] 0.4666171

The p-value of Kolmogorov-Smirnov test is less 2.2e-16 and

ks.test(log_mydata1, inv_jt_mydata1)
#    D = 0.53571, p-value < 2.2e-16
# alternative hypothesis: two-sided

CDFs are different: enter image description here

Edit 3.

library(Johnson)
  
set.seed(1)
n <- 252
log_mydata1 <- runif(n, min=-0.06, max= 0.05)

# Applying SU Johnson transformation

jt_mydata1<-RE.Johnson(log_mydata1)
z1 <- jt_mydata1$transformed; shapiro.test(z1) # W = 0.99495, p-value = 0.5748

mean(z1); sd(z1) # -0.02276707,  1.002103

# fpar1  <- ArimaModelFit(z1)
# Coefficients:
#         ar1     ar2      ar3      ma1      ma2  intercept
#      0.5520  0.4231  -0.1234  -0.5468  -0.4532    -0.0302
# s.e.  0.3582  0.3492   0.0666   0.3572   0.3570     0.0075


#ARMA  Simulation
sim1 <- arima.sim(list(order = c(3,0,2), 
                          ar = c(0.5520,  0.4231,  -0.1234), 
                          ma = c(-0.5468,  -0.4532)), n = n)

mean(sim1);sd(sim1) #  -0.0350542, 1.041598
shapiro.test(sim1)  # W = 0.99285, p-value = 0.2675

# convert an normalized variable back to a marginal variable    
gamma1   <- jt_mydata1$f.gamma
lambda1  <- jt_mydata1$f.lambda
epsilon1 <- jt_mydata1$f.epsilon
eta1     <- jt_mydata1$f.eta
# SU
# inv_jt_mydata1 <- lambda1 * sinh((sim1 - gamma1)/eta1) +  epsilon1
# SB
inv_jt_mydata1 <- ((lambda1 + epsilon1)* exp((sim1 - gamma1)/eta1) +  epsilon1)/(1+exp((sim1 - gamma1)/eta1))

The p-value of Kolmogorov-Smirnov test is $0.97$

ks.test(log_mydata1, inv_jt_mydata1)
#    D = 0.043651, p-value = 0.97
# alternative hypothesis: two-sided

and CDFs are close each to other:

enter image description here

added 1680 characters in body
Source Link
Nick
  • 856
  • 7
  • 25

Edit 2. I have changed the library to do the direct/back Johnson transformation:

library(Johnson)

set.seed(1)
n <- 252
log_mydata1 <- runif(n, min=-0.06, max= 0.05)

# Applying SU Johnson transformation

jt_mydata1<-RE.Johnson(log_mydata1)
z1 <- jt_mydata1$transformed; shapiro.test(z1) # W = 0.99495, p-value = 0.5748

mean(z1); sd(z1) # -0.02276707,  1.002103

# fpar1  <- ArimaModelFit(z1)
# Coefficients:
#         ar1     ar2      ar3      ma1      ma2  intercept
#      0.5520  0.4231  -0.1234  -0.5468  -0.4532    -0.0302
# s.e.  0.3582  0.3492   0.0666   0.3572   0.3570     0.0075


#ARMA  Simulation
sim1 <- arima.sim(list(order = c(3,0,2), 
                          ar = c(0.5520,  0.4231,  -0.1234), 
                          ma = c(-0.5468,  -0.4532)), n = n)

mean(sim1);sd(sim1) #  -0.0350542, 1.041598
shapiro.test(sim1)  # W = 0.99285, p-value = 0.2675

# convert an normalized variable back to a marginal variable    
gamma1   <- jt_mydata1$f.gamma
lambda1  <- jt_mydata1$f.lambda
epsilon1 <- jt_mydata1$f.epsilon
eta1     <- jt_mydata1$f.eta

inv_jt_mydata1 <- lambda1 * sinh((sim1 - gamma1)/eta1) +  epsilon1
mean(inv_jt_mydata1);sd(inv_jt_mydata1)
#[1] -0.09473195
#[1] 0.4666171

The p-value of Kolmogorov-Smirnov test is less 2.2e-16 and

ks.test(log_mydata1, inv_jt_mydata1)
#    D = 0.53571, p-value < 2.2e-16
# alternative hypothesis: two-sided

CDFs are different: enter image description here

Edit 2.

Edit 2. I have changed the library to do the direct/back Johnson transformation:

library(Johnson)

set.seed(1)
n <- 252
log_mydata1 <- runif(n, min=-0.06, max= 0.05)

# Applying SU Johnson transformation

jt_mydata1<-RE.Johnson(log_mydata1)
z1 <- jt_mydata1$transformed; shapiro.test(z1) # W = 0.99495, p-value = 0.5748

mean(z1); sd(z1) # -0.02276707,  1.002103

# fpar1  <- ArimaModelFit(z1)
# Coefficients:
#         ar1     ar2      ar3      ma1      ma2  intercept
#      0.5520  0.4231  -0.1234  -0.5468  -0.4532    -0.0302
# s.e.  0.3582  0.3492   0.0666   0.3572   0.3570     0.0075


#ARMA  Simulation
sim1 <- arima.sim(list(order = c(3,0,2), 
                          ar = c(0.5520,  0.4231,  -0.1234), 
                          ma = c(-0.5468,  -0.4532)), n = n)

mean(sim1);sd(sim1) #  -0.0350542, 1.041598
shapiro.test(sim1)  # W = 0.99285, p-value = 0.2675

# convert an normalized variable back to a marginal variable    
gamma1   <- jt_mydata1$f.gamma
lambda1  <- jt_mydata1$f.lambda
epsilon1 <- jt_mydata1$f.epsilon
eta1     <- jt_mydata1$f.eta

inv_jt_mydata1 <- lambda1 * sinh((sim1 - gamma1)/eta1) +  epsilon1
mean(inv_jt_mydata1);sd(inv_jt_mydata1)
#[1] -0.09473195
#[1] 0.4666171

The p-value of Kolmogorov-Smirnov test is less 2.2e-16 and

ks.test(log_mydata1, inv_jt_mydata1)
#    D = 0.53571, p-value < 2.2e-16
# alternative hypothesis: two-sided

CDFs are different: enter image description here

added 697 characters in body
Source Link
Nick
  • 856
  • 7
  • 25

Edit after @eric_kernfeld answer. I'd like to do

  1. Generate a time-series, for example, from a uniform distribution.

  2. Transform of non-normal variable to standard normal distribution.

  3. Fit an arima model to standard normal variable.

  4. Simulate from the arima model with the fitted parameters (in this case errors should be standard normal).

  5. Apply the back transformation that converts simulated arima output to marginal variable.

On the steps 2 and 5 I'm going to use the Johnson transformation and the back Johnson transformation respectively.

I have a time series and I'd like to do a simulation of log-returns using the normalization with Johnson distribution.

Finally, I'd like to inverseback the fitted data and to chectmarginal variable. I have applied the quality of simulation with Kolmogorov-Smirnov test and plotted Cumulative Distribution Functions (CDFs) of marginal (log-returns) and simulated (y) data to check the quality of 2, 3, 4, 5 step of simulation (normalization, arima, back transformation).

Questions. Am I correct in my steps? How to inverse correctly the Johnson normalized variable to a marginal variable? Should I use the qnorm() function?

Edit 2.

I have a time series and I'd like to do a simulation of log-returns using the normalization with Johnson distribution.

Finally, I'd like to inverse the fitted data and to chect the quality of simulation with Kolmogorov-Smirnov test and Cumulative Distribution Functions (CDFs) of marginal (log-returns) and simulated (y) data.

Questions. Am I correct in my steps? How to inverse correctly the Johnson normalized variable to a marginal variable? Should I use the qnorm() function?

Edit after @eric_kernfeld answer. I'd like to do

  1. Generate a time-series, for example, from a uniform distribution.

  2. Transform of non-normal variable to standard normal distribution.

  3. Fit an arima model to standard normal variable.

  4. Simulate from the arima model with the fitted parameters (in this case errors should be standard normal).

  5. Apply the back transformation that converts simulated arima output to marginal variable.

On the steps 2 and 5 I'm going to use the Johnson transformation and the back Johnson transformation respectively.

I have a time series and I'd like to do a simulation of log-returns using the normalization with Johnson distribution.

Finally, I'd like to back the fitted data to marginal variable. I have applied the Kolmogorov-Smirnov test and plotted Cumulative Distribution Functions (CDFs) of marginal (log-returns) and simulated (y) data to check the quality of 2, 3, 4, 5 step of simulation (normalization, arima, back transformation).

Questions. Am I correct in my steps? How to inverse correctly the Johnson normalized variable to a marginal variable? Should I use the qnorm() function?

Edit 2.

Notice added Canonical answer required by Nick
Bounty Started worth 50 reputation by Nick
added 3 characters in body; edited title
Source Link
Nick
  • 856
  • 7
  • 25
Loading
added 3 characters in body; edited title
Source Link
Nick
  • 856
  • 7
  • 25
Loading
added 836 characters in body; edited tags; edited title
Source Link
Nick
  • 856
  • 7
  • 25
Loading
added 54 characters in body
Source Link
Nick
  • 856
  • 7
  • 25
Loading
added 66 characters in body; edited title
Source Link
Nick
  • 856
  • 7
  • 25
Loading
added 66 characters in body; edited title
Source Link
Nick
  • 856
  • 7
  • 25
Loading
Source Link
Nick
  • 856
  • 7
  • 25
Loading