Learn R Programming

R2MLwiN (version 0.1-2)

predLines2: Draws predicted lines using chains from a model estimated using MCMC

Description

This function draws predicted lines against an explanatory variable for selected groups at a higher level. The median and quantiles are calculated for each group.

Usage

predLines2(indata, chains, resi.chains, xname, lev = 2, levID,
selected = NULL, probs=c(.025,.975), Legend=T)

Arguments

indata
A data.frame object containing the data modelled.
chains
The parameter chains from MLwiN.
resi.chains
The residual chains from MLwiN.
xname
A name of an explanatory variable.
lev
A digit indicating the level (of the multilevel model) at which to plot.
levID
A character (vector) specifying the level ID(s).
selected
A vector specifying groups to selectively plot at the level specified in lev. If selected=NULL, then all groups at that level are included.
probs
A numeric vector of probabilities with values in (0,1) used to calculate the lower and upper quantiles from which the error bars are plotted.
Legend
A logical value indicating whether a legend is to be added.

See Also

predLines1

Examples

Run this code
library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin = "C:/Program Files (x86)/MLwiN v2.26/"
## MLwiN sample worksheet folder
wspath=paste(mlwin,"/samples/",sep="")


## Example: Normal
formula="normexam~(0|cons+standlrt)+(2|cons+standlrt)+(1|cons)"
levID=c('school','student')
estoptions= list(EstM=1,resi.store.levs=2)
wsfile=paste(wspath,"tutorial.ws",sep="")
inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
mymodel=runMLwiN(formula, levID, D="Normal", indata, estoptions,MLwiNPath=mlwin)

resi.chains=mymodel["resi.chains"]
chains=mymodel["chains"]
predLines2(indata, chains, resi.chains, xname="standlrt", lev = 2, levID,
selected =c(30,44,53,59), probs=c(.025,.975))

Run the code above in your browser using DataLab