prediction.plot {MPTinR} | R Documentation |
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 |
model.filename |
Same as in |
dataset |
integer scalar or |
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 |
ylim |
the |
model.type |
Same as in |
args.plot |
|
args.rect |
|
args.box |
|
args.points |
|
args.labels |
|
numbers |
character vector (using partial matching) or |
pos.numbers |
character vector, indicating where to plot the points. Possible values are |
args.numbers |
|
args.abline |
|
abline |
logical. Whether to print vertical line at the positions of each point. If missing is set to |
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 plottingnumbers
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}))
Value
Invoked for its side effects, but invisibly returns a list
with the x and y positions for each point.
Note
Please report all problems.
Author(s)
Henrik Singmann. Thanks to David Kellen for discussion and ideas.
See Also
Examples
## 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)
## End(Not run)