Ultimos comentarios en Twitter

Sunday, 13 January 2013

R syntax for Mokken Scaling Analysis

RR syntax for Mokken Scaling Analysis (MSA)
Installing R
2. Click on Windows
3. Click on base
4. Click on Download R for Windows (the most recent version).
5. Click on Install R for the first time.
6. Click on Download R 3.0.1 for Windows.
7. Save the R-3.0.1-win.exe to your computer.
6. Run the R-3.0.1-win.exe from your computer and choose all the default values in the installation Wizard.

Installing MSA

1. Open R.
2. In the pull down menu choose Packages, Install package(s), choose a location nearby you, and choose the package ‘mokken’. MSA is now installed on your computer and need not be installed again.
3. If that does not work then use the following syntax:

> install.packages("mokken", dependencies=TRUE, repos="http://lib.stat.cmu.edu/R/CRAN")

Ignore any error messages and the Mokken package should load; you will know if no errors are returned after using the first command below.

Using MSA

Open R and type:

> library(mokken)

Converting an SPSS file for use in R

> library(foreign)

> FileR <- data.frame(read.spss("C:/FileSPSS.sav"))


You may get some errors or warnings at this stage which may have to be fixed before proceeding, then:

> fix(FileR)

This will show you the data as they appear in R, then:

> save(FileR, file = "C:/FileR.Rdata")

Once you have create an R file is can be uploaded again by:

> load("C:/FileR.Rdata")

Generating scales
To partition items in the FileR database into Mokken scales type:

> aisp(FileR)

Scalability coefficients
To produce scalability coefficients for items and the overall scale(s) type:
> coefH (FileR)

Mean item scores
To produce the mean values for all of the items in the scale type:
> apply(FileR,2,mean)

Monotonicity
To check monotonicity type:
> summary(check.monotonicity(FileR))

Plotting item step response functions
To plot item step response functions type:
> plot(check.monotonicity(FileR))
NB: if this does not work and you get:
*****Error in est - qnorm(1 - alpha.ci/2) * se : non-conformable arrays
In addition: Warning messages:
1: In (x - x^2)/n :
  longer object length is not a multiple of shorter object length****
this is a problem in R and you should use:
> plot(check.monotonicity(FileR), plot.ci = FALSE

Invariant item ordering
To check invariant item ordering type:
> summary(check.iio(FileR))

OR

> iio.results <- check.iio(FileR)
> summary(check.iio(FileR, item.selection = FALSE))

Generating pair plots
To generate pair plots:
> plot(check.iio(FileR))
The confidence intervals can be omitted by:
> plot(check.iio(FileR), plot.ci = FALSE)
To select item pairs, eg 1st, 3rd & 7th:
> plot(check.iio(FileR), item.pair = c(1, 3, 7) )

Saving plots
To save plots in a file (eg as pdf) in eg drive C:\
> NameOfFigure = "FileR.pdf"
> setwd("C:")
> pdf(NameOfFigure)
> plot(check.iio(FileR), ask = FALSE)
> dev.off()

Without confidence intervals
> NameOfFigure = "FileR.pdf"
> setwd("C:")
> pdf(NameOfFigure)
> plot(check.iio(FileR), plot.ci = FALSE, ask = FALSE)
> dev.off()

Additional information about plotting item pairs
# The complete command, where everything is set to default values
plot(check.iio(FileR), plot.ci = TRUE, color.ci = c("orange", "yellow"), alpha.ci = .05, ask = TRUE)

# Because default values can be omitted, the above command equals
plot(check.iio(FileR))

# Without colors
plot(check.iio(FileR), plot.ci = TRUE, color.ci = c("white", "white"), alpha.ci = .05, ask = TRUE)

# No more hitting Enters
plot(check.iio(FileR), plot.ci = TRUE, color.ci = c("white", "white"), alpha.ci = .05, ask = FALSE)

# Only the third item pair Pair1 = 1,2; Pair2 = 1,3; Pair3 = 1,4
plot(check.iio(FileR), item.pa

Reliability
To check reliability type:
> check.reliability(FileR)

Selecting items to analyse
To select specific items you need to create a new file as follows, type:
> FileRy <- FileR[ ,c(1,2,3,4)] - this will select items 1, 2, 3 & 4
> FileRy <- FileR[ ,c(1,2,3:10)] - this will select items 1, 2, 3, 4, 5, 6, 7, 8, 9 & 10
In both cases you analyse FileRy

Selecting individual for analysis
To select specific individuals you need to create a new file as follows, type:
> FileRx <- FileR[c(1,2:5)] - this will select individuals 1, 2, 3, 4 & 5

Removing R files from memory
> rm(list = ls())


Person item fit for polytomous data (with thanks to Jorge Tendeiro)

Load PerFit from R packages

NB: Ncat= number of response categories; Blvl=percentage cutoff level

> library(PerFit)
> load("C:/FileR.Rdata")
> x.Gnormedpoly <- Gnormed.poly(FileR, Ncat)
> plot(x.Gnormedpoly)
> Gnormedpoly.out <- Gnormed.poly(FileR, Ncat)
> Gnormedpoly.cut <- cutoff(Gnormedpoly.out, Blvl=.01)
> flagged.resp(Gnormedpoly.out, Gnormedpoly.cut, scores=FALSE)$PFSscores


> library(PerFit)
> load("G:/ItADL1PF.Rdata")
> x.Gnormedpoly <- Gnormed.poly(ItADL1PF, 5)
> plot(x.Gnormedpoly)
> Gnormedpoly.out <- Gnormed.poly(ItADL1PF, Ncat=5)
> Gnormedpoly.cut <- cutoff(Gnormedpoly.out, Blvl=.01)
> flagged.resp(Gnormedpoly.out, Gnormedpoly.cut, scores=FALSE)$PFSscores


When packages won’t load this syntax is useful:

install.packages("missing.package.name", repos=c("http://rstudio.org/_packages", "http://cran.rstudio.com"))



RW 25 July 2016

4 comments:

  1. Hi Roger,

    Thanks for this post, and for your blog! I am using Mokken scaling and the mokken R package for my dissertation research.

    I am encountering some trouble with Mokken analyses of a set of rating scale data because of the fact that not every rater rated each item. Have you encountered an incomplete data set in a Mokken analysis? Any thoughts about what to do?

    ReplyDelete
  2. Dear Stefanie

    Very glad you found the blog useful. I am afraid that there is not way within the Mokken scaling packages that I know of for taking into account missing data. It likes a complete data set so I usually just delete listwise the ones that are incomplete. Of course, if the missing data are random across the data set you can lose a lot of people. The only way to save the data that I know of is to impute - SPSS has a few very complicated options that I don't understand! The other way is to insert either a neutral value, if your data are polytomous, or to insert the mean value for the group for missing variables. However, these strategies depend on him mush is missing, as an estimate I'd say don't do this for missing data more than ten percent. I'll be very interested to hear more about your work. I am just reviewing a manuscript from a team in USA using Mokken scaling, unusual for the USA, it's usually only used in Europe.

    Roger

    ReplyDelete
  3. Thanks for your reply! I will continue to think about the problem.

    In the meantime, I do have another question about the plotting function for iio in the R package (if you don't mind):

    I am having trouble figuring out how the function determines the order in which the plots are presented. If I use (item.pairs = x), it seems logical for the first few items, but then the ordering seems odd. Any thoughts on this?

    ReplyDelete
  4. Sorry I did not notice this question; I am also sorry I can't really help as I am more or less totally dependent on Andries van der Ark for the syntax and any other advice - without him. R is just a mystery to me! He's very helpful if you email him.

    ReplyDelete