# WrightMap Tutorial – Part 2

March 24, 2014
By

(This article was first published on R Snippets for IRT, and kindly contributed to R-bloggers)

## Plotting Multidimensional & Polytomous Models

Remember: you can find the other parts of the tutorial here:

### Multidimensional models

In Part 1, we reviewed how to install the package from GitHub and how to customize unidimensional and dichotomous models. Now in Part 2, we’ll look at graphing some more complicated models.

(See Part 3 for ConQuest integration and making thresholds out of deltas.)

Of course, you will need to load `WrightMap` to begin with as shown in Part1. We will also need to load again RColorBrewer for some of the examples.

``library(RColorBrewer)``

First, let’s generate some thresholds for a multidimensional model. This will be a matrix containing five columns of person estimates.

``````mdim.sim.thetas <- matrix(rnorm(5000), ncol = 5)
``````

Since this will be a dichotomous model, we’ll generate a single column for thresholds.

``````mdim.sim.thresholds <- runif(10, -3, 3)
``````

Okay, let’s see what the Wright Map looks like for this.

``````wrightMap(mdim.sim.thetas, mdim.sim.thresholds)
``````

That doesn’t look right. Let’s adjust the proportion of the map’s parts.

``````wrightMap(mdim.sim.thetas, mdim.sim.thresholds, item.prop = 0.5)
``````

Let’s change the dimensions names

``````wrightMap(mdim.sim.thetas, mdim.sim.thresholds, item.prop = 0.5, dim.names = c("Algebra",
"Calculus", "Trig", "Stats", "Arithmetic"))
``````

And let’s give them some color

``````wrightMap(mdim.sim.thetas, mdim.sim.thresholds, item.prop = 0.5, dim.names = c("Algebra",
"Calculus", "Trig", "Stats", "Arithmetic"), dim.color = brewer.pal(5, "Set1"))
``````

And let’s associate the items with each dimension

``````wrightMap(mdim.sim.thetas, mdim.sim.thresholds, item.prop = 0.5, dim.names = c("Algebra",
"Calculus", "Trig", "Stats", "Arithmetic"), dim.color = brewer.pal(5, "Set1"),
show.thr.lab = FALSE, thr.sym.col.fg = rep(brewer.pal(5, "Set1"), each = 2),
thr.sym.col.bg = rep(brewer.pal(5, "Set1"), each = 2), thr.sym.cex = 2,
use.hist = FALSE)
``````

### Polytomous models

All right, let’s look at a Rating Scale Model. First, let’s generate three dimensions of person estimates.

``````rsm.sim.thetas <- data.frame(d1 = rnorm(1000, mean = -0.5, sd = 1), d2 = rnorm(1000,
mean = 0, sd = 1), d3 = rnorm(1000, mean = +0.5, sd = 1))
``````

Now let’s generate the thresholds for the polytomous items. We’ll make them a matrix where each row is an item and each column a level.

``````items.loc <- sort(rnorm(10))

rsm.sim.thresholds <- data.frame(l1 = items.loc - 1, l2 = items.loc - 0.5, l3 = items.loc +
0.5, l4 = items.loc + 1)

rsm.sim.thresholds
``````
``````##          l1       l2      l3      l4
## 1  -3.19202 -2.69202 -1.6920 -1.1920
## 2  -2.55843 -2.05843 -1.0584 -0.5584
## 3  -1.37052 -0.87052  0.1295  0.6295
## 4  -1.25838 -0.75838  0.2416  0.7416
## 5  -1.10905 -0.60905  0.3909  0.8909
## 6  -1.09854 -0.59854  0.4015  0.9015
## 7  -0.97131 -0.47131  0.5287  1.0287
## 8  -0.94265 -0.44265  0.5573  1.0573
## 9  -0.46542  0.03458  1.0346  1.5346
## 10 -0.04582  0.45418  1.4542  1.9542
``````

Let’s look at the Wright Map!

``````wrightMap(rsm.sim.thetas, rsm.sim.thresholds)
``````

Let’s assign a color for each level

``````itemlevelcolors <- matrix(rep(brewer.pal(4, "Set1"), 10), byrow = TRUE, ncol = 4)

itemlevelcolors
``````
``````##       [,1]      [,2]      [,3]      [,4]
##  [1,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [2,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [3,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [4,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [5,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [6,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [7,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [8,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
##  [9,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
## [10,] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
``````

And now make a Wright Map with them

``````wrightMap(rsm.sim.thetas, rsm.sim.thresholds, thr.sym.col.fg = itemlevelcolors,
thr.sym.col.bg = itemlevelcolors)
``````

But we also want to indicate which dimension they belong… with symbols

``````itemdimsymbols <- matrix(c(rep(16, 12), rep(17, 12), rep(18, 16)), byrow = TRUE,
ncol = 4)

itemdimsymbols
``````
``````##       [,1] [,2] [,3] [,4]
##  [1,]   16   16   16   16
##  [2,]   16   16   16   16
##  [3,]   16   16   16   16
##  [4,]   17   17   17   17
##  [5,]   17   17   17   17
##  [6,]   17   17   17   17
##  [7,]   18   18   18   18
##  [8,]   18   18   18   18
##  [9,]   18   18   18   18
## [10,]   18   18   18   18
``````
``````wrightMap(rsm.sim.thetas, rsm.sim.thresholds, show.thr.lab = FALSE, thr.sym.col.fg = itemlevelcolors,
thr.sym.col.bg = itemlevelcolors, thr.sym.pch = itemdimsymbols, thr.sym.cex = 2)
``````

### Changing the item axis

What happens if you have too many items?

``````rasch2.sim.thresholds <- runif(50, -3, 3)
``````

We use the defaults…

``````wrightMap(rnorm(1000), rasch2.sim.thresholds)
``````

Some options…

``````wrightMap(rnorm(1000), rasch2.sim.thresholds, show.thr.lab = FALSE, label.items.srt = 45)
``````

``````wrightMap(rnorm(1000), rasch2.sim.thresholds, show.thr.lab = FALSE, label.items.rows = 2)
``````

``````wrightMap(rnorm(1000), rasch2.sim.thresholds, show.thr.lab = FALSE, label.items = c("",
"example", 1:48), label.items.rows = 3)``````

Or you can get rid of that axis completely

``````wrightMap(rnorm(1000), rasch2.sim.thresholds, show.thr.sym = FALSE, thr.lab.text = paste("I",
1:50, sep = ""), label.items = "", label.items.ticks = FALSE)
``````

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...