Import surveys, combine into single data frame, delete identifying information, assign IDs, and separate out by scale for item examination.
# https://hansjoerg.me/2018/04/23/rasch-in-r-tutorial/
knitr::knit_hooks$set(
error = function(x, options) {
paste('\n\n<div class="alert alert-danger">',
gsub('##', '\n', gsub('^##\ Error', '**Error**', x)),
'</div>', sep = '\n')
},
warning = function(x, options) {
paste('\n\n<div class="alert alert-warning">',
gsub('##', '\n', gsub('^##\ Warning:', '**Warning**', x)),
'</div>', sep = '\n')
},
message = function(x, options) {
paste('\n\n<div class="alert alert-info">',
gsub('##', '\n', x),
'</div>', sep = '\n')
}
)
# load libraries ----------------------------------------------------------
library(stringi)
library(psych)
library(DT)
library(naniar)
library(UpSetR)
library(nFactors)
library(lavaan)
library(corrplot)
library(tidyr)
library(ggplot2)
library(dplyr)
library("eRm")
library("ltm")
library("difR")
library("psych")
# load data ---------------------------------------------------------------
# alt <- read.csv(file="UBelong Post-Survey Pitt OChem Spring 2022 Alternative Scales_April 28, 2022_12.34.csv", header=T)
# alt <- alt[-c(1,2),]
# alt$scale <- "alt"
#
# orig <- read.csv(file="UBelong Post-Survey Pitt OChem Spring 2022 Original Scales_April 28, 2022_12.35.csv", header=T)
# orig <- orig[-c(1,2),]
# orig$scale <- "orig"
#
# df <- rbind.data.frame(alt, orig)
# df <- subset(df, select = -c(1:19))
# names(df)
# myFun <- function(n) {
# a <- do.call(paste0, replicate(5, sample(LETTERS, n, TRUE), FALSE))
# paste0(a, sprintf("%04d", sample(9999, n, TRUE)), sample(LETTERS, n, TRUE))
# }
# df$id <- myFun(nrow(df))
# write.csv(df, file="imported_anonymized.csv", row.names = F)
df <- read.csv(file="imported_anonymized.csv", header=T)
# extract items -----------------------------------------------------------
# new items
EEochem <- subset(df, select=c(scale,grep("EEochem", colnames(df)))) # entry expectations
CCdisc <- subset(df, select=c(scale,grep("CCdisc", colnames(df)))) # classroom climate
IDochem <- cbind.data.frame(subset(df, select=c(scale,grep("IDochem", colnames(df)))), subset(df, select=grep("FASochem", colnames(df)))) # identity
CSochem <- subset(df, select=grep("CSochem", colnames(df))) # career satisfaction
# established scales
MSchem <- subset(df, select=c(scale,grep("MSchem", colnames(df)))) # discipline growth mindset (chemistry)
IPchem <- subset(df, select=c(scale,grep("IPchem", colnames(df)))) # instructor growth mindset (chemistry)
SEchem <- subset(df, select=grep("SEchem", colnames(df))) # disciplinary self-efficacy (chemistry)
MSochem <- subset(df, select=c(scale, grep("MSochem", colnames(df)))) # disciplinary growth mindset (organic chemistry)
IPochem <- subset(df, select=grep("IPochem", colnames(df))) # instructor growth mindset (organic chemistry)
SEochem <- subset(df, select=grep("SEochem", colnames(df))) # disciplinary self-efficacy (organic chemistry)
CNEBochem_class <- cbind.data.frame(subset(subset(df, select=grep("CNEBochem", colnames(df))), select=c(1:3))) # entity norms and beliefs
CNEBochem_self <- cbind.data.frame(subset(subset(df, select=grep("CNEBochem", colnames(df))), select=c(4:6))) # entity norms and beliefs
CNHSochem_others <- cbind.data.frame(subset(subset(df, select=grep("CNHSochem", colnames(df))), select=c(1:3))) # help seeking
CNHSochem_self <- cbind.data.frame(subset(subset(df, select=grep("CNHSochem", colnames(df))), select=c(4:6))) # help seeking
CNSWochem <- subset(df, select=grep("CNSWochem", colnames(df))) # help seeking
FCochem <- subset(df, select=grep("FCochem", colnames(df))) # faculty caring
IPchem$IPchem04_rc[IPchem$IPchem04 == 1] <- 4
IPchem$IPchem04_rc[IPchem$IPchem04 == 2] <- 3
IPchem$IPchem04_rc[IPchem$IPchem04 == 3] <- 2
IPchem$IPchem04_rc[IPchem$IPchem04 == 4] <- 1
IPchem$IPchem04 <- IPchem$IPchem04_rc
IPchem <- subset(IPchem, select=-c(IPchem04_rc))
d <- subset(IPchem, scale == "orig", select=-c(scale))
IPchem_desc <- data.frame(describe(d))
datatable(subset(IPchem_desc, select=-c(n, trimmed, mad))) %>%
formatRound(1:10) %>%
formatStyle(8:9, color = styleInterval(c(-2, 2), c('red', 'black', 'red')))
vis_miss(d)
# gg_miss_upset(EEochem)
ggplot(gather(d), aes(value)) +
geom_histogram(bins = 4) +
facet_wrap(~key)
corr <- corr.test(d, adjust = "holm")
rval <- corr$r
rval[lower.tri(corr$r, diag = T)] <- NA
datatable(rval) %>%
formatRound(1:ncol(rval)) %>%
formatStyle(1:ncol(rval), color = styleInterval(c(-.7, .7), c('red', 'black', 'red')))
corrplot(corr$r)
d <- na.omit(d)
ev <- eigen(cor(d))
ap <- parallel(subject=nrow(d),var=ncol(d),rep=100,cent=.05)
nS <- nScree(x=ev$values, aparallel=ap$eigen$qevpea)
plotnScree(nS)
EFA <- factanal(d, factors = 1, rotation = "promax", cutoff = 0.3)
print(EFA, digits=3, cutoff=.0, sort=TRUE)
##
## Call:
## factanal(x = d, factors = 1, rotation = "promax", cutoff = 0.3)
##
## Uniquenesses:
## IPchem02 IPchem03 IPchem04 IPchem05
## 0.723 0.005 0.927 0.984
##
## Loadings:
## [1] 0.526 0.997 0.270 -0.127
##
## Factor1
## SS loadings 1.361
## Proportion Var 0.340
##
## Test of the hypothesis that 1 factor is sufficient.
## The chi square statistic is 18.07 on 2 degrees of freedom.
## The p-value is 0.000119
d <- subset(IPchem, scale == "alt", select=-c(scale))
IPchem_desc <- data.frame(describe(d))
datatable(subset(IPchem_desc, select=-c(n, trimmed, mad))) %>%
formatRound(1:10) %>%
formatStyle(8:9, color = styleInterval(c(-2, 2), c('red', 'black', 'red')))
vis_miss(d)
# gg_miss_upset(EEochem)
ggplot(gather(d), aes(value)) +
geom_histogram(bins = 4) +
facet_wrap(~key)
Warning Removed 6 rows containing non-finite values (stat_bin).
corr <- corr.test(d, adjust = "holm")
rval <- corr$r
rval[lower.tri(corr$r, diag = T)] <- NA
datatable(rval) %>%
formatRound(1:ncol(rval)) %>%
formatStyle(1:ncol(rval), color = styleInterval(c(-.7, .7), c('red', 'black', 'red')))
corrplot(corr$r)
d <- na.omit(d)
ev <- eigen(cor(d))
ap <- parallel(subject=nrow(d),var=ncol(d),rep=100,cent=.05)
nS <- nScree(x=ev$values, aparallel=ap$eigen$qevpea)
plotnScree(nS)
EFA <- factanal(d, factors = 1, rotation = "promax", cutoff = 0.3)
print(EFA, digits=3, cutoff=.0, sort=TRUE)
##
## Call:
## factanal(x = d, factors = 1, rotation = "promax", cutoff = 0.3)
##
## Uniquenesses:
## IPchem02 IPchem03 IPchem04 IPchem05
## 0.547 0.339 0.798 0.992
##
## Loadings:
## [1] 0.673 0.813 0.449 -0.091
##
## Factor1
## SS loadings 1.324
## Proportion Var 0.331
##
## Test of the hypothesis that 1 factor is sufficient.
## The chi square statistic is 3.3 on 2 degrees of freedom.
## The p-value is 0.192
d <- subset(IPchem, scale == "orig", select=-c(scale))
d <- d %>%
mutate_at(vars(1:ncol(d)), recode, `1` = 0, `2` = 0, `3` = 1, `4` = 1)
d1 <- subset(d, select=c(IPchem02, IPchem03, IPchem04))
d <- d1
mod2 <- ltm(d ~ z1)
summary(mod2)
##
## Call:
## ltm(formula = d ~ z1)
##
## Model Summary:
## log.Lik AIC BIC
## -147.925 307.85 322.2167
##
## Coefficients:
## value std.err z.vals
## Dffclt.IPchem02 -0.9600 0.3990 -2.4063
## Dffclt.IPchem03 0.1031 0.2003 0.5147
## Dffclt.IPchem04 0.6146 0.3145 1.9540
## Dscrmn.IPchem02 1.5563 1.0299 1.5111
## Dscrmn.IPchem03 1.7081 1.0979 1.5557
## Dscrmn.IPchem04 1.2192 0.6155 1.9809
##
## Integration:
## method: Gauss-Hermite
## quadrature points: 21
##
## Optimization:
## Convergence: 0
## max(|grad|): 0.0042
## quasi-Newton: BFGS
item.fit(mod2, simulate.p.value=T)
##
## Item-Fit Statistics and P-values
##
## Call:
## ltm(formula = d ~ z1)
##
## Alternative: Items do not fit the model
## Ability Categories: 10
## Monte Carlo samples: 100
##
## X^2 Pr(>X^2)
## IPchem02 44.4591 0.5941
## IPchem03 42.7976 0.5347
## IPchem04 59.2391 0.4257
plot.ltm(mod2, type = 'ICC', auto.key = FALSE)
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
plot.ltm(mod2, type = 'IIC', auto.key = FALSE)
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
items <- colnames(d)
n <- 1
for (i in 1:ncol(d)) {
plot.ltm(mod2, type = 'ICC', auto.key = FALSE, items = n, main = items[n], annot = F)
n <- n + 1
}
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
items <- colnames(d)
n <- 1
for (i in 1:ncol(d)) {
plot.ltm(mod2, type = 'IIC', auto.key = FALSE, items = n, main = items[n], annot = F)
n <- n + 1
}
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
plot(mod2, type=c("IIC"), items=c(0), ylim=c(0,2.1))
d <- subset(IPchem, scale == "alt", select=-c(scale))
d <- d %>%
mutate_at(vars(1:ncol(d)), recode, `1` = 0, `2` = 0, `3` = 1, `4` = 1)
d1 <- subset(d, select=c(IPchem02, IPchem03, IPchem04))
d <- d1
mod2 <- ltm(d ~ z1)
summary(mod2)
##
## Call:
## ltm(formula = d ~ z1)
##
## Model Summary:
## log.Lik AIC BIC
## -174.5745 361.149 376.8988
##
## Coefficients:
## value std.err z.vals
## Dffclt.IPchem02 -1.1948 0.3389 -3.5256
## Dffclt.IPchem03 -0.1744 0.1612 -1.0824
## Dffclt.IPchem04 0.1648 0.2057 0.8014
## Dscrmn.IPchem02 1.9135 1.0015 1.9106
## Dscrmn.IPchem03 2.2822 1.4038 1.6257
## Dscrmn.IPchem04 1.3364 0.5566 2.4013
##
## Integration:
## method: Gauss-Hermite
## quadrature points: 21
##
## Optimization:
## Convergence: 0
## max(|grad|): 0.0012
## quasi-Newton: BFGS
item.fit(mod2, simulate.p.value=T)
##
## Item-Fit Statistics and P-values
##
## Call:
## ltm(formula = d ~ z1)
##
## Alternative: Items do not fit the model
## Ability Categories: 10
## Monte Carlo samples: 100
##
## X^2 Pr(>X^2)
## IPchem02 49.0220 0.5347
## IPchem03 39.2038 0.5842
## IPchem04 70.5562 0.5446
plot.ltm(mod2, type = 'ICC', auto.key = FALSE)
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
plot.ltm(mod2, type = 'IIC', auto.key = FALSE)
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in text.default(z[pos[it]], pr[pos[it], itms[it]], labels = nams[it], :
“auto.key” is not a graphical parameter
items <- colnames(d)
n <- 1
for (i in 1:ncol(d)) {
plot.ltm(mod2, type = 'ICC', auto.key = FALSE, items = n, main = items[n], annot = F)
n <- n + 1
}
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
items <- colnames(d)
n <- 1
for (i in 1:ncol(d)) {
plot.ltm(mod2, type = 'IIC', auto.key = FALSE, items = n, main = items[n], annot = F)
n <- n + 1
}
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
Warning in plot.window(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy, type, …): “auto.key” is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, …): “auto.key” is not a
graphical parameter
Warning in box(…): “auto.key” is not a graphical parameter
Warning in title(…): “auto.key” is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, …): “auto.key” is not a
graphical parameter
plot(mod2, type=c("IIC"), items=c(0), ylim=c(0,2.1))