Learn R Programming

DPpackage (version 1.1-0)

Plm: Bayesian analysis for a parametric linear regression model

Description

This function generates a posterior density sample from a parametric linear regression model using a normal distribution of the errors.

Usage

Plm(formula,prior,mcmc,state,status,
     data=sys.frame(sys.parent()),na.action=na.fail)

Arguments

formula
a two-sided linear formula object describing the model fit, with the response on the left of a ~ operator and the terms, separated by + operators, on the right.
prior
a list giving the prior information. The list includes the following parameter: tau1 and tau2 giving the hyperparameters for the prior distribution of the error variance,
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
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
data
data frame.
na.action
a function that indicates what should happen when the data contain NAs. The default action (na.fail) causes Plm to print an error message and terminate if there are any

Value

  • An object of class Plm representing the parametric linear regression model fit. Generic functions such as print, plot, summary, and anova have methods to show the results of the fit. The results include beta, and sigma2. 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:
  • betagiving the value of the regression coefficients.
  • sigma2giving the error variance.

Details

This generic function fits a linear regression model: $$y_i = X_i \beta + V_i, i=1,\ldots,n$$ $$V_i | \sigma^2 \sim N(0,\sigma^2)$$ To complete the model specification, independent hyperpriors are assumed, $$\beta | \beta_0, S_{\beta_0} \sim N(\beta_0, S_{\beta_0})$$ $$\sigma^{-2} | \tau_1, \tau_2 \sim Gamma(\tau_1/2,\tau_2/2)$$

Examples

Run this code
############################################
    # The Australian Institute of Sport's data
    ############################################
      data(sports)
      attach(sports)

    # Initial state
      state <- NULL

    # MCMC parameters

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

    # Prior information
      prior <- list(beta0=rep(0,3),
                    Sbeta0=diag(1000,3),
                    tau1=0.01,
                    tau2=0.01)

    # Fit the model

      fit <- Plm(formula=bmi~lbm+gender,prior=prior,mcmc=mcmc,
                  state=state,status=TRUE) 

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

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

    # Table of Pseudo Contour Probabilities
      anova(fit)

Run the code above in your browser using DataLab