Ultimos comentarios en Twitter

Sunday, 1 December 2013

A method for calculating item misplacement

I have been struggling to think of a way to calculate and compare the difference in the ordering of items between different Mokken scales, eg different samples or between small and large samples from the same population. The problem is that you need a reference point and that should be the definitive ordering of the items; something that we can only know in theory but, in practice - unless we sample the whole population - we can't know.  So, what about a very large sample - in the region of 10,000 - that we can assume gives the ordering in the real population?

So, we have the reference point, how do we compare the ordering in sub-samples.  We can count the number of times an item is not in its usual place in the reference ordering, seems sensible, but the problem is that when one item is out of place there must be at least two items out of place as another one will be moved in the hierarchy. The misplacement of any single item means that another is automatically misplaced but we do not know which one was misplaced first. The solution is simple, calculate the total number of items misplaced and subtract 1; therefore, the number of misplaced items - compared with a reference sample - is 'm - 1' where 'm' is the number of misplaced items. The '- 1' accounts for the item that has to move for any misplacement of items to occur. In this way it should be possible to compare different samples from the same population or from a very large sample and to study, for example, the effect of taking different samples or a series of samples of the same size or a series of sample of a different size.

Admittedly, the point I am making is quite minor.  However, whether or not you take the '-1' correction into account any comparisons will be the same but - while the minimum number of misplaced items is clearly zero - then it is more sensible to have the next smallest number as '1' and then the sequence continues up to 'n-1' where 'n' is the number of items in the scale.  Therefore, for a scale of 'n' items the maximum number of misplaced items is 'n-1' because if all the items are displaced then 'n = m'; again accounting for the fact that if all items are misplaced then the minimum number of misplacement that needed to occur was 1.

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