Saturday, December 30, 2017

R-Programming for Item Response theory of binomial data(chandigarh)


R-Programming is very useful for different stages of Questionnaire construction. There are three phases of questionnaire constuction mainly, These are

1. Item examination
1.1 Summary of items
>x=read.csv(choose.files(),header=T,sep=",")
>str(x)
>attach(x)
#extract set of items (n=64)
>safe_item=data.frame(x[18:81])
#Checking
> str(x1[1])
>names(x1)
> names(x1)
 [1] "Item_1"  "Item_2"  "Item_3"  "Item_4"  "Item_5"  "Item_6"  "Item_7"  "Item_8" 
 [9] "Item_9"  "Item_10" "Item_11" "Item_12" "Item_13" "Item_14" "Item_15" "Item_16"
[17] "Item_17" "Item_18" "Item_19" "Item_20" "Item_21" "Item_22" "Item_23" "Item_24"
[25] "Item_25" "Item_26" "Item_27" "Item_28" "Item_29" "Item_30" "Item_31" "Item_32"
[33] "Item_33" "Item_34" "Item_35" "Item_36" "Item_37" "Item_38" "Item_39" "Item_40"
[41] "Item_41" "Item_42" "Item_43" "Item_44" "Item_45" "Item_46" "Item_47" "Item_48"
[49] "Item_49" "Item_50" "Item_51" "Item_52" "Item_53" "Item_54" "Item_55" "Item_56"
[57] "Item_57" "Item_58" "Item_59" "Item_60" "Item_61" "Item_62" "Item_63" "Item_64"


'data.frame': 351 obs. of  1 variable:
 $ Item_1: int  1 1 1 1 1 1 1 1 1 1 ...
> str(x1[64])
'data.frame': 351 obs. of  1 variable:
 $ Item_64: int  1 0 0 1 0 1 0 1 1 1 ...
>summary(x1)
Item_64      
 Min.   :0.0000  
 1st Qu.:0.0000  
 Median :1.0000  
 Mean   :0.5983  
 3rd Qu.:1.0000  
 Max.   :1.0000
>dataframe=x1
>save(dataframe,file='F:/chandigarh/collected data/dataframe.R')

# Cleaning missing data
x1=na.omit(x1)

2. Package installation

>install.packages("psych")
>library(psych)
>sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_India.1252  LC_CTYPE=English_India.1252   
[3] LC_MONETARY=English_India.1252 LC_NUMERIC=C                  
[5] LC_TIME=English_India.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] psych_1.7.8

loaded via a namespace (and not attached):
[1] parallel_3.3.2  tools_3.3.2     foreign_0.8-67  nlme_3.1-128    mnormt_1.5-5   
[6] grid_3.3.2      lattice_0.20-34


3. Item description

First check descriptive statistics

>describe(safe_item) " safe_item is data frame
        vars   n mean   sd median trimmed mad min max range  skew kurtosis   se
Item_1     1 351 0.98 0.15      1    1.00   0   0   1     1 -6.37    38.66 0.01
Item_2     2 351 0.85 0.35      1    0.94   0   0   1     1 -2.00     2.02 0.02

4. Inter-Item relations
> round(cor(x1,use="pair"),2)  
        Item_1 Item_2 Item_3 Item_4 Item_5 Item_6 Item_7 Item_8 Item_9 Item_10
Item_1    1.00  -0.01   0.06   0.24   0.06   0.02   0.01   0.19   0.09    0.01
Item_2   -0.01   1.00   0.19   0.10   0.22   0.01   0.12   0.10   0.16    0.28
Item_3    0.06   0.19   1.00   0.29   0.06   0.16   0.14   0.20   0.18    0.19
Item_4    0.24   0.10   0.29   1.00   0.09   0.27  -0.05   0.23   0.05    0.18
Item_5    0.06   0.22   0.06   0.09   1.00   0.06   0.17   0.10   0.11    0.06
Item_6    0.02   0.01   0.16   0.27   0.06   1.00  -0.07   0.07   0.16    0.11
Item_7    0.01   0.12   0.14  -0.05   0.17  -0.07   1.00   0.17   0.23    0.01
Item_8    0.19   0.10   0.20   0.23   0.10   0.07   0.17   1.00   0.05    0.15
Item_9    0.09   0.16   0.18   0.05   0.11   0.16   0.23   0.05   1.00    0.18
Item_10   0.01   0.28   0.19   0.18   0.06
Scatterplot
>pairs.panels(safe_item[1:4])
A scatter plot matrix (splom) of a data set is a a powerful way to examine a data set. Elements on the diagonal show the histograms and densities of the data, lower off diagonal elements are the pairwise scatter plots, upper off diagonal elements are the pairwise correlations.

5. Error.bar
Error bars are graphical representations of the variability of data and used on graphs to indicate the error or uncertainty in a reported measurement. They give a general idea of how precise a measurement is, or conversely, how far from the reported value the true (error free) value might be. Error bars often represent one standard deviation of uncertainty, one standard error, or a particular confidence interval (e.g., a 95% interval).

>error.bars(safe_item[1:5])
Image may contain: text

5. Internal consistency

> alpha(x1[1:19], keys=NULL,cumulative=FALSE, title=NULL, max=10,na.rm = TRUE,
+       check.keys=FALSE,n.iter=1,delete=TRUE,use="pairwise",warnings=TRUE,n.obs=NULL)

Reliability analysis 
Call: alpha(x = x1[1:19], keys = NULL, cumulative = FALSE, title = NULL,
    max = 10, na.rm = TRUE, check.keys = FALSE, n.iter = 1, delete = TRUE,
    use = "pairwise", warnings = TRUE, n.obs = NULL)

  raw_alpha std.alpha G6(smc) average_r S/N  ase mean   sd
      0.74      0.75    0.79      0.14 3.1 0.02 0.86 0.14

 lower alpha upper     95% confidence boundaries
0.71 0.74 0.78

 Reliability if an item is dropped:
        raw_alpha std.alpha G6(smc) average_r S/N alpha se
Item_1       0.74      0.75    0.79      0.14 3.0    0.020
Item_2       0.73      0.74    0.78      0.14 2.9    0.021
Item_3       0.73      0.74    0.78      0.14 2.9    0.021
Item_4       0.73      0.73    0.77      0.13 2.8    0.021
Item_5       0.74      0.75    0.79      0.14 3.0    0.020
Item_6       0.74      0.75    0.79      0.14 3.0    0.020
Item_7       0.74      0.75    0.79      0.15 3.1    0.020
Item_8       0.73

6. Item-Response theory

>install.packages("ltm")
>library(ltm)
>data<-read.csv(file.choose(),header=T,sep=",")
>irtmodel<-ltm(data~z1,IRT.param=TRUE)
> coef(irtmodel)
               Dffclt       Dscrmn
Item_1   -3.800517707  1.139506095
Item_2   -2.316439196  0.881119322
Item_3   -2.289122504  1.022710642
Item_4   -2.157115564  2.138582759

> plot(irtmodel,type="ICC")
No automatic alt text available.

>plot(irtmodel,type="ICC",items=1)

>plot(irtmodel,type="ICC",items=20)

No automatic alt text available.

>plot(irtmodel,type="ICC",items=40:50)

>plot(irtmodel,type="IIC",items=0)

No automatic alt text available.


Test information function

>info1=information(irtmodel,c(-4,0))
> info2=information(irtmodel,c(0,4))

> info1

Call:
ltm(formula = data ~ z1, IRT.param = TRUE)

Total Information = 56.68
Information in (-4, 0) = 40.28 (71.06%)
Based on all the items

> info2

Call:
ltm(formula = data ~ z1, IRT.param = TRUE)

Total Information = 56.68
Information in (0, 4) = 10.69 (18.86%)
Based on all the items

>

No comments:

Post a Comment