FilconCoKappaJags

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

FilconCoKappaJags

Ulf Ahlstrom
I looked in previous posts but couldn't see this question posted before:  Is it possible to make a within-subjects version of the "FilconCoKappaJags" code?  Any suggestion would be helpful.

model {
   for ( subjIdx in 1:nSubj ) {
      # Likelihood:
      z[subjIdx] ~ dbin( theta[subjIdx] , N[subjIdx] )
       
      # Prior on theta: Notice nested indexing.
      theta[subjIdx] ~ dbeta( a[cond[subjIdx]] , b[cond[subjIdx]] )T(0.001,0.999)
   }
   for ( condIdx in 1:nCond ) {
      a[condIdx] <- mu[condIdx] * kappa[condIdx]
      b[condIdx] <- (1-mu[condIdx]) * kappa[condIdx]
      # Hyperprior on mu and kappa:
      mu[condIdx] ~ dbeta( Amu , Bmu )
      kappa[condIdx] ~ dgamma( Skappa , Rkappa )
   }
   # Constants for hyperprior:
   Amu <- 1
   Bmu <- 1
   Skappa <- pow(meanGamma,2)/pow(sdGamma,2)
   Rkappa <- meanGamma/pow(sdGamma,2)
   meanGamma ~ dunif( 0.01 , 30 )
   sdGamma ~ dunif( 0.01 , 30 )
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FilconCoKappaJags

John K. Kruschke
Administrator
Hi Ulf.

Within-subject designs are challenging because there are multiple ways to approach them, depending on how the data are arranged within subjects.

Ideally, there are lots of data collected within each subject, so that each subject can be modeled individually with a fully-parameterized model. Then you can put higher-level distributions over the individual-subject parameters to get some shrinkage informed by other subjects. Conceptually, this is the most straight-forward approach. An example in DBDA is the hierarchical linear regression for the data in Fig. 16.10. In that example, each subject was modeled with linear regression, and then there were higher level distributions put over the individual parameters.

This kind of approach can be taken for ANOVA-style models too. For simplicity, you might not want to put a shrinkage prior within every individual, as the model gets unwieldy (in code and concept). Thus, for every individual, estimate the deflection parameters, but maybe do not estimate the variance of the deflections within subjects. Instead put a higher-level distribution on the corresponding deflections across subjects. But there is no uniquely "correct" model -- after all, we're just trying to meaningfully and accurately describe the data. So, you could include an estimated individual-subject deflection variance, but put an across-subject higher-level distribution for shrinkage.

If you have only a single datum per cell within each subject, then you cannot use a fully-parameterized model for every subject, because the parameters are not identifiable (i.e., the interaction term absorbs all the noise variance). Then you have to decide on some other model (see, e.g., the "split plot" design in the blog).

Sorry to reply in such vague generalities...


On Fri, Sep 27, 2013 at 8:54 AM, Ulf Ahlstrom [via Doing Bayesian Data Analysis] <[hidden email]> wrote:
I looked in previous posts but couldn't see this question posted before:  Is it possible to make a within-subjects version of the "FilconCoKappaJags" code?  Any suggestion would be helpful.

model {
   for ( subjIdx in 1:nSubj ) {
      # Likelihood:
      z[subjIdx] ~ dbin( theta[subjIdx] , N[subjIdx] )
       
      # Prior on theta: Notice nested indexing.
      theta[subjIdx] ~ dbeta( a[cond[subjIdx]] , b[cond[subjIdx]] )T(0.001,0.999)
   }
   for ( condIdx in 1:nCond ) {
      a[condIdx] <- mu[condIdx] * kappa[condIdx]
      b[condIdx] <- (1-mu[condIdx]) * kappa[condIdx]
      # Hyperprior on mu and kappa:
      mu[condIdx] ~ dbeta( Amu , Bmu )
      kappa[condIdx] ~ dgamma( Skappa , Rkappa )
   }
   # Constants for hyperprior:
   Amu <- 1
   Bmu <- 1
   Skappa <- pow(meanGamma,2)/pow(sdGamma,2)
   Rkappa <- meanGamma/pow(sdGamma,2)
   meanGamma ~ dunif( 0.01 , 30 )
   sdGamma ~ dunif( 0.01 , 30 )
}


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

Loading...