Learn R Programming

DPpackage (version 1.1-0)

DPMraschpoisson: Bayesian analysis for a semiparametric Rasch Poisson model

Description

This function generates a posterior density sample for a semiparametric Rasch Poisson model, using a DPM of normals prior for the distribution of the random effects.

Usage

DPMraschpoisson(y,prior,mcmc,offset=NULL,state,status,
        grid=seq(-10,10,length=1000),data=sys.frame(sys.parent()),
        compute.band=FALSE)

Arguments

y
a matrix giving the data for which the Rasch Poisson Model is to be fitted.
prior
a list giving the prior information. The list includes the following parameter: N giving the truncation of the Dirichlet process prior, a0 and b0 givi
mcmc
a list giving the MCMC parameters. The list must include the following integers: nburn giving the number of burn-in scans, nskip giving the thinning interval, nsave giving
offset
this can be used to specify an a priori known component to be included in the linear predictor during the fitting.
state
a list giving the current value of the parameters. This list is used if the current analysis is the continuation of a previous analysis.
status
a logical variable indicating whether this run is new (TRUE) or the continuation of a previous analysis (FALSE). In the latter case the current value of the parameters must be specifie
grid
grid points where the density estimate is evaluated. The default is seq(-10,10,length=1000).
data
data frame.
compute.band
logical variable indicating whether the confidence band for the density and CDF must be computed.

Value

  • An object of class DPMrasch representing the Rasch model fit. Generic functions such as print, plot, and summary have methods to show the results of the fit. The results include beta, mub, sigmab, sigmak2, the precision parameter alpha, and the number of clusters. The function DPrandom can be used to extract the posterior mean of the random effects. The list state in the output object contains the current value of the parameters necessary to restart the analysis. If you want to specify different starting values to run multiple chains set status=TRUE and create the list state based on this starting values. In this case the list state must include the following objects:
  • alphagiving the value of the precision parameter.
  • ba vector of dimension nsubjects giving the value of the random effects for each subject.
  • betagiving the value of the difficulty parameters.
  • nclusteran integer giving the number of clusters.
  • ssan interger vector defining to which of the ncluster clusters each subject belongs.
  • muclusa vector of dimension N giving the value of the normal means.
  • sigmaclusa vector of dimension N giving the value of the normal variances.
  • mubgiving the mean of the normal baseline distributions.
  • sigmabgiving the variance of the normal baseline distributions.
  • tauk2giving the parameter of the inverse-gamma prior for the normal kernel variances.
  • wdpgiving the vector of DP weights.
  • vdpgiving the vector of stick-breaking beta random variables used to create the DP weights.

Details

This generic function fits a semiparametric Rasch Poisson model as in San Martin et al. (2009), where $$\eta_{ij} = \theta_i - \beta_j, i=1,\ldots,n, j=1,\ldots,k$$ $$\theta_i | G \sim \int N(\mu,\sigma) G(d\mu,\sigma)$$ $$\beta | \beta_0, S_{\beta_0} \sim N(\beta_0,S_{\beta_0})$$ $$G | \alpha, G_0 \sim DP(\alpha G_0)$$ where $G_0 = N(\mu |\mu_b, \sigma_b) IG(\sigma|\tau_{k1},\tau_{k_2})$. To complete the model specification, independent hyperpriors are assumed, $$\alpha | a_0, b_0 \sim Gamma(a_0,b_0)$$ $$\mu_b | m0, s0 \sim N(m0,s0)$$ $$\sigma_b^{-2} | \tau_{b1}, \tau_{b2} \sim Gamma(\tau_{b1}/2,\tau_{b2}/2)$$ $$\tau_{k2} | \tau_{s1}, \tau_{s2} \sim Gamma(\tau_{s1}/2,\tau_{s2}/2)$$ The precision or total mass parameter, $\alpha$, of the DP prior can be considered as random, having a gamma distribution, $Gamma(a_0,b_0)$, or fixed at some particular value. To let $\alpha$ to be fixed at a particular value, set $a_0$ to NULL in the prior specification. The computational implementation of the model is based on the finite approximation for DP proposed by Ishwaran and James (2002). The full conditional distributions for the difficulty parameters and in the resampling step of random effects are generated through the Metropolis-Hastings algorithm with a IWLS proposal (see, West, 1985 and Gamerman, 1997).

References

Gamerman, D. (1997) Sampling from the posterior distribution in generalized linear mixed models. Statistics and Computing, 7: 57-68.

Ishwaran, H. and James, L.F. (2002) Approximate Dirichlet process computing finite normal mixtures: smoothing and prior information. Journal of Computational and Graphical Statistics, 11:508-532. San Martin, E., Jara, A., Rolin, J.-M., and Mouchart, M. (2009) On the Analysis of Bayesian Semiparametric IRT-type Models. In preparation. West, M. (1985) Generalized linear models: outlier accomodation, scale parameter and prior distributions. In Bayesian Statistics 2 (eds Bernardo et al.), 531-558, Amsterdam: North Holland.

See Also

DPrandom, DPraschpoisson, FPTraschpoisson

Examples

Run this code
####################################
    # A simulated Data Set
    ####################################
      nsubject <- 250
      nitem <- 2
      
      y <- matrix(0,nrow=nsubject,ncol=nitem)
      dimnames(y)<-list(paste("id",seq(1:nsubject)), 
                                       paste("item",seq(1,nitem)))

      ind <- rbinom(nsubject,1,0.5)
      theta <- ind*rnorm(nsubject,-1,0.5)+(1-ind)*rnorm(nsubject,2,0.25)
      beta <- c(0,seq(-3,3,length=nitem-1))

      true.density <- function(grid)
      {
            0.5*dnorm(grid,-1,0.5)+0.5*dnorm(grid,2,0.25)  
      } 

      true.cdf <- function(grid)
      {
            0.5*pnorm(grid,-1,0.5)+0.5*pnorm(grid,2,0.25)  
      } 

      for(i in 1:nsubject)
      {
         for(j in 1:nitem)
         {
            eta <- theta[i]-beta[j]         
            rate <- exp(eta)
            y[i,j] <- rpois(1,rate)
         }
      }

    # Prior information

      beta0 <- rep(0,nitem-1)
      Sbeta0 <- diag(100,nitem-1)

      prior <- list(N=50,
                          a0=2,
                          b0=0.1,
                          taub1=6.01,
                          taub2=2.01,
                          taus1=6.01,
                          taus2=2.01,
                          tauk1=6.01,
                          m0=0,
                          s0=100,
                          beta0=beta0,
                          Sbeta0=Sbeta0)

    # Initial state
      state <- NULL      

    # MCMC parameters

      nburn <- 5000
      nsave <- 5000
      nskip <- 0
      ndisplay <- 100
      mcmc <- list(nburn=nburn,
                            nsave=nsave,
                            nskip=nskip,
                            ndisplay=ndisplay)

    # Fit the model
      fit1 <- DPMraschpoisson(y=y,prior=prior,mcmc=mcmc,
                              state=state,status=TRUE,grid=seq(-3,4,0.01))
   
      plot(fit1$grid,fit1$dens.m,type="l",lty=1,col="red",xlim=c(-3,4),ylim=c(0,0.8))
      lines(fit1$grid,true.density(fit1$grid),lty=2,col="blue")

      plot(fit1$grid,fit1$cdf.m,type="l",lty=1,col="red")
      lines(fit1$grid,true.cdf(fit1$grid),lty=2,col="blue")

    # Summary with HPD and Credibility intervals
      summary(fit1)
      summary(fit1,hpd=FALSE)

    # Plot model parameters 
    # (to see the plots gradually set ask=TRUE)
      plot(fit1,ask=FALSE)
      plot(fit1,ask=FALSE,nfigr=2,nfigc=2)	

    # Extract random effects
    
      DPrandom(fit1)
      plot(DPrandom(fit1))
      DPcaterpillar(DPrandom(fit1))

Run the code above in your browser using DataLab