MPTinR (version 1.11.0)

prediction.plot: Plot observed versus predicted values for categorical data.

Description

Plot observed minus predicted responses from a cognitive model for categorical data fit with MPTinR. Values above 0 indicate that there are to many responses in that category compared to the predictions, values below 0 indicate that there are to little responses compared to the predictions.

Usage

prediction.plot(results, model.filename, 
dataset = 1, 
absolute = TRUE, 
spacing = 2, 
axis.labels = NULL, 
ylim, model.type = c("easy", "eqn", "eqn2"), 
args.plot = list(), args.rect = list(), args.box = list(), args.points = list(), 
args.labels = list(), numbers = c("individual", "continuous"), 
pos.numbers = c("plot", "axis"), args.numbers = list(), args.abline = list(), abline)

Arguments

results

list. Results from fit.mpt, fit.model, or fit.mptinr.

model.filename

Same as in fit.mpt.

dataset

integer scalar or "aggregated" defining which dataset to plot.

absolute

logical. Should absolute deviations (the default) or G^2 deviations be plotted. See Details.

spacing

The spacing between two trees in x-axis ticks.

axis.labels

The labels on the x-axis. Default is Tree 1 to codeTree n.

ylim

the ylim argument to plot. If missing taken from data.

model.type

Same as in fit.mpt.

args.plot

list. Further arguments to plot, see details.

args.rect

list. Further arguments to rect, see details.

args.box

list. Further arguments to box, see details.

args.points

list. Further arguments to points, see details.

args.labels

list. Further arguments to axis, see details.

numbers

character vector (using partial matching) or NULL indicating where/if to plot numbers. Possible values are "individual", "continuous", or NULL. "individual" will start with 1 for the first response category in each tree/item type. "continuous" will use consecutive numbering matching the column numbers/ position of the data, NULL will plot no numbers. The default plots "individual" numbers.

pos.numbers

character vector, indicating where to plot the points. Possible values are "plot" or "axis" (using partial matching).

args.numbers

list. Further arguments to either text (if pos.numbers = "plot") or axis (if pos.numbers = "axis"), see details.

args.abline

list. Further arguments to abline, see details.

abline

logical. Whether to print vertical line at the positions of each point. If missing is set to TRUE if pos.numbers = "axis".

Value

Invoked for its side effects, but invisibly returns a list with the x and y positions for each point.

Details

This function uses base graphics to produce the plots and calls the following functions in the order given to do so: plot (produces an empty plot with axes), rect (produces the shaded area for each tree/ item type), box (produces another box around the plot), possibly abline (produces the vertical lines for each point), points (adds the data points), and depending on the value of numbers and pos.numbers either text (adds the numbers in the plot) or axis (adds the numbers below the plot).

For all of those functions default values are set but can be changed using the corresponding argument. These argument must be a named list containing arguments to that function (see Examples). Default arguments are:

  • args.plot: list(xlab = "", ylab = "", main = "")

  • args.rect: list(col = "grey", border = "transparent", density = 30, angle = 45)

  • args.box: nothing

  • args.points: list(pch = 1, cex = 2.25)

  • args.labels: either list(line = -1) or if plotting numbers at "axis", list(line = 1)

  • args.numbers (if pos.numbers = "plot"): list(labels = as.character(numbers.pch), cex = 0.7) (If you change "labels" you can define what to plot instead of numbers).

  • args.numbers (if pos.numbers = "axis"): list(labels = numbers.pch, cex.axis = 0.6, mgp = c(0,0.3,0)) (If you change "labels" you can define what to plot instead of numbers)

  • args.abline: list(col = "darkgrey").

If absolute = TRUE (the default) absolute deviations are plotted (i.e., observed - predicted from the model). If absolute = FALSE G^2 values are plotted which are computed for all predictions where data is non 0 with: $$2 \times \mbox{data} \times (log(\mbox{data}) - log(\mbox{predictions}))$$

See Also

fit.mpt

Examples

Run this code
# NOT RUN {
#### using the model and data from Broeder & Schuetz:
data(d.broeder, package = "MPTinR")
m.2htm <- system.file("extdata", "5points.2htm.model", package = "MPTinR")
m.sdt <- "pkg/MPTinR/inst/extdata/broeder.sdt.model"

m.sdt <- system.file("extdata", "broeder.sdt.model", package = "MPTinR")

# fit the 2HTM
br.2htm <- fit.mpt(d.broeder, m.2htm)

# graphical parameters
par(mfrow = c(2,2))
prediction.plot(br.2htm, m.2htm, 4)
prediction.plot(br.2htm, m.2htm, 4, ylim = c(-4, 4), numbers = NULL, 
	args.points = list(pch = 16, cex = 1.5))
prediction.plot(br.2htm, m.2htm, 4, ylim = c(-4, 4), args.plot = list(main = "Dataset 4 - A"),
	abline = TRUE, numbers = "continuous")
prediction.plot(br.2htm, m.2htm, 4, ylim = c(-4, 4), args.plot = list(main = "Dataset 4 - B"),
	pos.numbers = "axis", abline = TRUE, 
	args.numbers = list(mgp = c(3, 0.2, 0), cex.axis = 0.35),
	args.points = list(pch = 4, cex = 1.5))
dev.off()

prediction.plot(br.2htm, m.2htm, "aggregated", axis.labels = unlist(lapply(c(10, 25, 50, 75, 90),
	paste, c("o.o", "o.n"), sep = "")))

# fit the SDT
br.sdt <- fit.model(d.broeder, m.sdt, lower.bound = c(rep(-Inf, 5), 0, 1), upper.bound = Inf)

axis.labels <- unlist(lapply(c(10, 25, 50, 75, 90), paste, c("o.o", "o.n"), sep = ""))
# compare predictions for aggregated data:
par(mfrow = c(2,2))
prediction.plot(br.2htm, m.2htm, "aggregated", ylim = c(-30, 30), 
	args.plot = list(main = "MPT model - absolute"), axis.labels = axis.labels)
prediction.plot(br.sdt, m.2htm, "aggregated", ylim = c(-30, 30),
	args.plot = list(main = "SDT model - absolute"), axis.labels = axis.labels)
prediction.plot(br.2htm, m.2htm, "aggregated", ylim = c(-60, 60), 
	args.plot = list(main = "MPT model - G.squared"), absolute = FALSE, 
	axis.labels = axis.labels, pos.numbers = "axis", args.points = list(pch = 8, cex = 1))
prediction.plot(br.sdt, m.2htm, "aggregated", ylim = c(-60, 60),
	args.plot = list(main = "SDT model - G.squared"), absolute = FALSE, 
	axis.labels = axis.labels, pos.numbers = "axis", args.points = list(pch = 8, cex = 1))

# comparing absoulte and G-sqaured plot with zero counts in cell 2:
par(mfrow = c(2,2))
prediction.plot(br.2htm, m.2htm, 2, ylim = c(-1, 1),
	args.plot = list(main = "MPT model - absolute"))
prediction.plot(br.sdt, m.2htm, 2, ylim = c(-1, 1),
	args.plot = list(main = "SDT model - absolute"))
prediction.plot(br.2htm, m.2htm, 2, ylim = c(-2, 2),
	args.plot = list(main = "MPT model - G.squared"), absolute = FALSE)
prediction.plot(br.sdt, m.2htm, 2, ylim = c(-2, 2),
	args.plot = list(main = "SDT model - G.squared"), absolute = FALSE)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab