Log Normal Multiple Linear Regression

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Log Normal Multiple Linear Regression

Greg
I'm trying to adapt the MultipleLinearRegression model (BMLR.R) to model data that is the mean taken a log-normal distribution.  When I change the model I'm getting an error as follows:

"Error in jags.model("model.txt", data = dataList, inits = initsList, n.chains = nChains,  :
  Error in node y[1]
Observed node inconsistent with unobserved parents at initialization"

This is the entire code:

You'll notice that I changed dnorm to dlnorm, and I also changed dunif to dgamma for tau, with the idea that the conjugate prior for a log-normal should be a normal (mu) and gamma (tau).  I tried it with tau being both uniform and gamma and got the same message.

All the data is >0, so that shouldn't be a problem.

I'm a newbie, so any help you can provide would be great.
______________
# THE MODEL.
  modelstring = "
  # JAGS model specification begins here...
  model {
    # Likelihood:
    for( i in 1:N ) {
      y[i] ~ dlnorm( y.hat[i] , tau )
      y.hat[i] <- b0 +  inprod( b[1:nPred] , x[i,1:nPred] )
    }
    # Prior (assumes standardized data):
    tau <- log(1/pow(sigma,2))^2
    sigma ~ dgamma ( .0001 , 10 ) #changed to dgamma from dunif
    b0 ~ dnorm( .0001 , 1.0E-2 )
    for ( j in 1:nPred ) {
      b[j] ~ dnorm( .0001 , 1.0E-2 )
    }
  }
  # ... end JAGS model specification
  " # close quote for modelstring
  writeLines(modelstring,con="model.txt")
 
_____________
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Normal Multiple Linear Regression

John K. Kruschke
Administrator

dlnorm is confusing because its parameters are on the scale of log(y), not y. In other words, if you specify

y[i] ~ dlnorm( mu , 1/sigma^2 )

then the estimated mu and sigma are the mean and standard deviation of log(y[i]) described by a normal distribution. In other words, mu and sigma are not the mean and standard deviation of y[i].

The easiest way to make sense of dlnorm is, often, not to use dlnorm at all. Instead, just take the log of all the y values and describe log(y) with the usual normal-disribution models.

If you must use dlnorm, just remember that the mu and sigma parameters are for log(y) described with a normal distribution, which means you don't have to mess with the priors by taking logs. Just use the usual priors on mu and sigma, remembering that they are describing log(y) not y.

Here's another way of saying it: If you use the usual normal distribution model on log(y), the parameter estimates are the same as if you use dlnorm on y (without changing the prior).


On Fri, Apr 26, 2013 at 2:02 PM, Greg [via Doing Bayesian Data Analysis] <[hidden email]> wrote:
I'm trying to adapt the MultipleLinearRegression model (BMLR.R) to model data that is the mean taken a log-normal distribution.  When I change the model I'm getting an error as follows:

"Error in jags.model("model.txt", data = dataList, inits = initsList, n.chains = nChains,  :
  Error in node y[1]
Observed node inconsistent with unobserved parents at initialization"

This is the entire code:

You'll notice that I changed dnorm to dlnorm, and I also changed dunif to dgamma for tau, with the idea that the conjugate prior for a log-normal should be a normal (mu) and gamma (tau).  I tried it with tau being both uniform and gamma and got the same message.

All the data is >0, so that shouldn't be a problem.

I'm a newbie, so any help you can provide would be great.
______________
# THE MODEL.
  modelstring = "
  # JAGS model specification begins here...
  model {
    # Likelihood:
    for( i in 1:N ) {
      y[i] ~ dlnorm( y.hat[i] , tau )
      y.hat[i] <- b0 +  inprod( b[1:nPred] , x[i,1:nPred] )
    }
    # Prior (assumes standardized data):
    tau <- log(1/pow(sigma,2))^2
    sigma ~ dgamma ( .0001 , 10 ) #changed to dgamma from dunif
    b0 ~ dnorm( .0001 , 1.0E-2 )
    for ( j in 1:nPred ) {
      b[j] ~ dnorm( .0001 , 1.0E-2 )
    }
  }
  # ... end JAGS model specification
  " # close quote for modelstring
  writeLines(modelstring,con="model.txt")
 
_____________


If you reply to this email, your message will be added to the discussion below:
http://doing-bayesian-data-analysis.12272.x6.nabble.com/Log-Normal-Multiple-Linear-Regression-tp5000650.html
To start a new topic under Doing Bayesian Data Analysis, email [hidden email]
To unsubscribe from Doing Bayesian Data Analysis, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Normal Multiple Linear Regression

John K. Kruschke
Administrator
In reply to this post by Greg

P.S. You may ask, "Okay, the parameters of dlnorm are on the scale of log(y)... so what the parameters on the original scale of y?" Answer: For mu and sigma on log(y) scale:
mu_y = exp( mu + sigma^2/2 )
sigma_y = sqrt( exp( 2*mu + sigma^2 ) * ( exp(sigma^2) - 1 ) )




On Fri, Apr 26, 2013 at 2:02 PM, Greg [via Doing Bayesian Data Analysis] <[hidden email]> wrote:
I'm trying to adapt the MultipleLinearRegression model (BMLR.R) to model data that is the mean taken a log-normal distribution.  When I change the model I'm getting an error as follows:

"Error in jags.model("model.txt", data = dataList, inits = initsList, n.chains = nChains,  :
  Error in node y[1]
Observed node inconsistent with unobserved parents at initialization"

This is the entire code:

You'll notice that I changed dnorm to dlnorm, and I also changed dunif to dgamma for tau, with the idea that the conjugate prior for a log-normal should be a normal (mu) and gamma (tau).  I tried it with tau being both uniform and gamma and got the same message.

All the data is >0, so that shouldn't be a problem.

I'm a newbie, so any help you can provide would be great.
______________
# THE MODEL.
  modelstring = "
  # JAGS model specification begins here...
  model {
    # Likelihood:
    for( i in 1:N ) {
      y[i] ~ dlnorm( y.hat[i] , tau )
      y.hat[i] <- b0 +  inprod( b[1:nPred] , x[i,1:nPred] )
    }
    # Prior (assumes standardized data):
    tau <- log(1/pow(sigma,2))^2
    sigma ~ dgamma ( .0001 , 10 ) #changed to dgamma from dunif
    b0 ~ dnorm( .0001 , 1.0E-2 )
    for ( j in 1:nPred ) {
      b[j] ~ dnorm( .0001 , 1.0E-2 )
    }
  }
  # ... end JAGS model specification
  " # close quote for modelstring
  writeLines(modelstring,con="model.txt")
 
_____________


If you reply to this email, your message will be added to the discussion below:
http://doing-bayesian-data-analysis.12272.x6.nabble.com/Log-Normal-Multiple-Linear-Regression-tp5000650.html
To start a new topic under Doing Bayesian Data Analysis, email [hidden email]
To unsubscribe from Doing Bayesian Data Analysis, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Normal Multiple Linear Regression

Greg
In reply to this post by John K. Kruschke
I really appreciate all the help.  

So, to select my data values, (evidence) I have a data set that follows a log normal distribution.  The central tendency of that data is described by the geometric mean, which should be the log(arithmetic mean), correct?

Log(Y[i])~dnorm(mu, tau)

Should I use the arithmetic mean of my data set as mu, or do we take the geometric mean as mu to use in the above equation?

This is a great forum for helping those of us new to applying Bayesian concepts.  Thanks for all the help.  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Normal Multiple Linear Regression

John K. Kruschke
Administrator

Maybe this blog post will help:
http://doingbayesiandataanalysis.blogspot.com/2013/04/bayesian-estimation-of-log-normal.html
Or maybe not?

On Sat, Apr 27, 2013 at 8:39 PM, Greg [via Doing Bayesian Data Analysis] <[hidden email]> wrote:
I really appreciate all the help.  

So, to select my data values, (evidence) I have a data set that follows a log normal distribution.  The central tendency of that data is described by the geometric mean, which should be the log(arithmetic mean), correct?

Log(Y[i])~dnorm(mu, tau)

Should I use the arithmetic mean of my data set as mu, or do we take the geometric mean as mu to use in the above equation?

This is a great forum for helping those of us new to applying Bayesian concepts.  Thanks for all the help.  




If you reply to this email, your message will be added to the discussion below:
http://doing-bayesian-data-analysis.12272.x6.nabble.com/Log-Normal-Multiple-Linear-Regression-tp5000650p5000653.html
To start a new topic under Doing Bayesian Data Analysis, email [hidden email]
To unsubscribe from Doing Bayesian Data Analysis, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Normal Multiple Linear Regression

Greg
That explains it perfectly.  Thanks so much.  
Loading...