if (require(ggplot2)==FALSE){
install.packages("ggplot2")
}
## Loading required package: ggplot2
library(ggplot2)
if (require(reshape2) == FALSE){
install.packages("reshape2")
}
## Loading required package: reshape2
if (require(lavaan) == FALSE){
install.packages("lavaan")
}
## Loading required package: lavaan
## This is lavaan 0.5-23.1097
## lavaan is BETA software! Please report any bugs.
library(lavaan)
if (require(psych) == FALSE){
install.packages("psych")
}
## Loading required package: psych
##
## Attaching package: 'psych'
## The following object is masked from 'package:lavaan':
##
## cor2cov
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
if (require(pander) == FALSE){
install.packages("pander")
}
## Loading required package: pander
if (require(sjPlot) == FALSE){
install.packages("sjPlot")#To get iten discrimination.
}
## Loading required package: sjPlot
if (require(semPlot) == FALSE){
install.packages("semPlot")
}
## Loading required package: semPlot
if (require(base) == FALSE){
install.packages("base")#it has the "round" function.
}
if (require(dplyr) == FALSE){
install.packages("dplyr")
}
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#if (require(corrr) == FALSE){
# install.packages("corrr")
#}
#install.packages ("stats")
#library(stats)
setwd("~/Dropbox/EPSY906/HWs/HW05")
dat <- read.csv("Presence_Scales_HW05.csv")
#dat<-dat0[,-1]
#pander(names(dat))
This instrument has three latent constructs to measure one latent trait called “presence”" in online community of inquiry framework (CoI). These constructs are: Cognitive Presence (CP), Teaching Presence (TP), and Social Presence (SP). The Community of Inquiry framework is a theoretical position that posits “higher order learning is bestsupported in a community of learners engaged in critical reflection and discourse” (Garrison, Cleveland-Innes, & Fung 2010, p. 32). Several studies (e.g., Bennet, Priest, & Macpherson, 1999; Ludwig-Hardman & Dunlap,2003; Lowenthal, & Dunlap, 2010) have reported that students feel detached and isolated in online learning environments. These constructs are critical in online learning environments when instructors plan to enhance their salience in invisible social context. These constructs play significant roles in online community. Social presence, for example, correlates strongly with students’ overall perceived learning and overall perceived satisfaction with instructor (Richardson & Swan, 2003). Therefore, the author is interested in measuring student perceptions of teacher presence in the online courses. This survey is designed to measure three aspects of classroom presence, including:
Teaching Presence: Design and facilitation of the course to promote learning
Cognitive Presence: Learning and inquiry processes,
Social Presence: Identification with a community of other learners in the course,
The instrument includes 18 items. For this CoI framework evaluation, there are six items for each construct (Teaching, Cognitive, and Social Presence) to be representative of the construct and also to provide “short-form” measures of these three constructs (18 items, 6 per subscale). Each scale is built on a likert scale with five point responses.
Here are the items:
Cognitive Presence:
CP1: I felt motivated to explore content related questions.
CP2: Problems posed increased my interest in course issues.
CP3: I can apply the knowledge created in this course to my work or other non-class related activities.
CP4: Learning activities helped me construct explanations/solutions.
CP5: I have developed solutions to course problems that can be applied in practice.
CP6: I can describe ways to test and apply the knowledge created in this course.
Teaching Presence:
TP1: The instructor clearly communicated important course goals.
TP2: The instructor was helpful in guiding the class towards understanding course topics in a way that helped me clarify my thinking.
TP3: The instructor provided clear instructions on how to participate in course learning activities.
TP4: The instructor was helpful in identifying areas of agreement and disagreement on course topics that helped me to learn.
TP5: The instructor helped to keep course participants in productive dialogue.
TP6: The instructor provided feedback in a timely fashion.
Social Presence:
SP1: I felt comfortable conversing through the online medium.
SP2: I felt comfortable participating in the course discussions.
SP3: The instructor helped keep the course participants on task in a way that helped me to learn.
SP4: I felt comfortable disagreeing with other course participants while still maintaining a sense of trust.
SP5: I felt that my point of view was acknowledged by other course participants.
SP6: Getting to know other course participants gave me a sense of belonging in the course.
The sample:
The sample, students enrolled in online courses at a wide range of diverse higher education institutions in the United States, was recruited through Amazon.com’s Mechanical Turk (MTurk), an online system for recruiting research participants across the globe. A total of 709 students responded to the survey. The average age of the sample is 29.18. Out of the 709 participants, there were 394 females, 315 males. 484 White/Caucasian (68.3%), 74 Black/African American (10.4%), 74 Asian/Pacific Island (10.4%), three American Indian/Alaskan Native (0.4%), 30 Hispanic (4.2%), two Other (0.3%), and 42 multi- multiethnic (5.9%) online learners.
A confirmatory factor analysis (CFA) was conducted in R version 1.1 (R Core Team, 2016), using WLSMV estimator in lavaan (Rosseel, 2012) and using sempath (Epskamp and Stuber, 2017) packages. ` When evaluating the goodness of fit of the model, the author uses four fit indices and criteria as follow to evaluate the results:
Root Mean Square Error of Approximation (RMSEA) ranges from 0 to 1 ;smaller is better. Based on the documented literature, RMSEA < .05 or .06 = “good”, .05 to .08 = “acceptable”,.08 to .10 = “mediocre”, and >.10 = “unacceptable”. Standardized Root Mean Square Residual (SRMR) ranges from 0 to 1: smaller is better “.08 or less” indicates good fit. -Root Mean Square Residual (RMR) ranges from 0 to 1: smaller is better “.08 or less” indicates good fit. -Comparative Fit Index (CFI): it ranges from <0 to >1, bigger is better, >.95 is considered as a “good” fit index. -Tucker-LewisIndex (Non-Normed Fit Index, TLI) also ranges from <0 to >1, bigger is better, >.95 is considered as a “good” fit index, From <0 to >1, bigger is better, >.95 = “good”.
The author conducted all models (Cognitive Presence, Teaching Presence, and Social Presence) constraining the mean of each factor equal to zero and each factor’s variance is equal to 1. All the models were conducted using WLSMV as an estimator method, and standatdized loadings.
library("MVN")
## sROC 0.1-2 loaded
##
## Attaching package: 'MVN'
## The following object is masked from 'package:psych':
##
## mardia
# Pull out the items for Cognitive Presence Scale:
x_vars <- dat[,paste("CP", c(1,2,3,4,5,6), sep="")]
uniPlot(x_vars, type = "histogram")
grm2PsyntaxCP1 = "
CP =~ CP1 + CP2 + CP3 + CP4 + CP5 + CP6
CP ~~ 1*CP
CP ~ 0"
grm2PestimatesCP1 = cfa(model = grm2PsyntaxCP1, data = dat, ordered = c("CP1", "CP2", "CP3", "CP4", "CP5", "CP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 14 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesCP1, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 45 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 43.656 112.623
## Degrees of freedom 9 9
## P-value (Chi-square) 0.000 0.000
## Scaling correction factor 0.390
## Shift parameter 0.563
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 10492.568 5417.454
## Degrees of freedom 15 15
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.997 0.981
## Tucker-Lewis Index (TLI) 0.994 0.968
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.074 0.128
## 90 Percent Confidence Interval 0.053 0.096 0.107 0.149
## P-value RMSEA <= 0.05 0.033 0.000
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.035 0.035
##
## Weighted Root Mean Square Residual:
##
## WRMR 1.058 1.058
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP =~
## CP1 1.112 0.068 16.446 0.000 1.112 0.744
## CP2 0.672 0.043 15.655 0.000 0.672 0.558
## CP3 1.005 0.058 17.301 0.000 1.005 0.709
## CP4 1.383 0.075 18.363 0.000 1.383 0.810
## CP5 1.955 0.121 16.210 0.000 1.955 0.890
## CP6 1.743 0.095 18.377 0.000 1.743 0.867
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP 0.000 0.000 0.000
## .CP1 0.000 0.000 0.000
## .CP2 0.000 0.000 0.000
## .CP3 0.000 0.000 0.000
## .CP4 0.000 0.000 0.000
## .CP5 0.000 0.000 0.000
## .CP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP1|t1 -3.225 0.176 -18.352 0.000 -3.225 -2.157
## CP1|t2 -2.029 0.104 -19.461 0.000 -2.029 -1.357
## CP1|t3 -1.288 0.087 -14.826 0.000 -1.288 -0.861
## CP1|t4 1.099 0.079 13.908 0.000 1.099 0.735
## CP2|t1 -2.116 0.096 -22.004 0.000 -2.116 -1.757
## CP2|t2 -1.167 0.067 -17.442 0.000 -1.167 -0.968
## CP2|t3 -0.295 0.058 -5.113 0.000 -0.295 -0.245
## CP2|t4 1.100 0.065 16.986 0.000 1.100 0.913
## CP3|t1 -2.804 0.138 -20.372 0.000 -2.804 -1.978
## CP3|t2 -1.886 0.092 -20.473 0.000 -1.886 -1.330
## CP3|t3 -1.035 0.075 -13.726 0.000 -1.035 -0.730
## CP3|t4 0.829 0.070 11.766 0.000 0.829 0.585
## CP4|t1 -3.892 0.237 -16.398 0.000 -3.892 -2.281
## CP4|t2 -2.567 0.126 -20.345 0.000 -2.567 -1.504
## CP4|t3 -1.401 0.097 -14.422 0.000 -1.401 -0.821
## CP4|t4 1.145 0.086 13.296 0.000 1.145 0.671
## CP5|t1 -4.736 0.306 -15.500 0.000 -4.736 -2.157
## CP5|t2 -3.101 0.168 -18.425 0.000 -3.101 -1.412
## CP5|t3 -1.633 0.132 -12.374 0.000 -1.633 -0.744
## CP5|t4 1.613 0.126 12.776 0.000 1.613 0.735
## CP6|t1 -4.333 0.249 -17.387 0.000 -4.333 -2.157
## CP6|t2 -2.896 0.147 -19.699 0.000 -2.896 -1.441
## CP6|t3 -1.679 0.119 -14.113 0.000 -1.679 -0.836
## CP6|t4 1.420 0.105 13.485 0.000 1.420 0.707
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP 1.000 1.000 1.000
## .CP1 1.000 1.000 0.447
## .CP2 1.000 1.000 0.689
## .CP3 1.000 1.000 0.498
## .CP4 1.000 1.000 0.343
## .CP5 1.000 1.000 0.207
## .CP6 1.000 1.000 0.248
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP1 0.669 0.669 1.000
## CP2 0.830 0.830 1.000
## CP3 0.705 0.705 1.000
## CP4 0.586 0.586 1.000
## CP5 0.455 0.455 1.000
## CP6 0.498 0.498 1.000
##
## R-Square:
## Estimate
## CP1 0.553
## CP2 0.311
## CP3 0.502
## CP4 0.657
## CP5 0.793
## CP6 0.752
fitmeasures(grm2PestimatesCP1)
## npar fmin
## 30.000 0.031
## chisq df
## 43.656 9.000
## pvalue chisq.scaled
## 0.000 112.623
## df.scaled pvalue.scaled
## 9.000 0.000
## chisq.scaling.factor baseline.chisq
## 0.390 10492.568
## baseline.df baseline.pvalue
## 15.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 5417.454 15.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 1.939
## cfi tli
## 0.997 0.994
## nnfi rfi
## 0.994 0.993
## nfi pnfi
## 0.996 0.598
## ifi rni
## 0.997 0.997
## cfi.scaled tli.scaled
## 0.981 0.968
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.968 NA
## rfi.scaled nfi.scaled
## 0.965 0.979
## ifi.scaled rni.scaled
## 0.979 0.990
## rni.robust rmsea
## NA 0.074
## rmsea.ci.lower rmsea.ci.upper
## 0.053 0.096
## rmsea.pvalue rmsea.scaled
## 0.033 0.128
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.107 0.149
## rmsea.pvalue.scaled rmsea.robust
## 0.000 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.031
## rmr_nomean srmr
## 0.035 0.035
## srmr_bentler srmr_bentler_nomean
## 0.031 0.035
## srmr_bollen srmr_bollen_nomean
## 0.031 0.035
## srmr_mplus srmr_mplus_nomean
## 0.031 0.035
## cn_05 cn_01
## 275.390 352.376
## gfi agfi
## 0.997 0.989
## pgfi mfi
## 0.230 0.976
resid(grm2PestimatesCP1)
## $type
## [1] "raw"
##
## $cov
## CP1 CP2 CP3 CP4 CP5 CP6
## CP1 0.000
## CP2 0.070 0.000
## CP3 -0.019 -0.029 0.000
## CP4 0.056 0.023 0.009 0.000
## CP5 -0.071 -0.064 0.035 -0.026 0.000
## CP6 -0.028 -0.003 -0.033 -0.038 0.033 0.000
##
## $mean
## CP1 CP2 CP3 CP4 CP5 CP6
## 0 0 0 0 0 0
##
## $th
## CP1|t1 CP1|t2 CP1|t3 CP1|t4 CP2|t1
## 1.360055e-06 -2.212246e-07 3.994204e-07 1.692976e-07 -1.739875e-07
## CP2|t2 CP2|t3 CP2|t4 CP3|t1 CP3|t2
## 8.365463e-07 3.626585e-07 8.633379e-07 -3.128776e-08 1.386026e-07
## CP3|t3 CP3|t4 CP4|t1 CP4|t2 CP4|t3
## -1.361074e-08 -6.873915e-08 6.536136e-07 3.275200e-07 -4.903913e-07
## CP4|t4 CP5|t1 CP5|t2 CP5|t3 CP5|t4
## -2.068167e-07 9.465990e-07 4.867034e-07 -9.827038e-07 9.149630e-07
## CP6|t1 CP6|t2 CP6|t3 CP6|t4
## -8.446305e-07 5.328163e-07 5.119853e-07 -9.310299e-07
modificationindices(grm2PestimatesCP1, sort. = TRUE)
## lhs op rhs mi mi.scaled epc sepc.lv sepc.all sepc.nox
## 65 CP5 ~~ CP6 19.902 51.088 0.601 0.601 0.136 0.136
## 54 CP1 ~~ CP5 14.027 36.007 -0.409 -0.409 -0.125 -0.125
## 53 CP1 ~~ CP4 12.260 31.470 0.262 0.262 0.102 0.102
## 51 CP1 ~~ CP2 9.551 24.517 0.172 0.172 0.096 0.096
## 58 CP2 ~~ CP5 7.923 20.337 -0.249 -0.249 -0.094 -0.094
## 64 CP4 ~~ CP6 5.515 14.156 -0.261 -0.261 -0.076 -0.076
## 61 CP3 ~~ CP5 5.138 13.190 0.219 0.219 0.070 0.070
## 63 CP4 ~~ CP5 3.554 9.122 -0.225 -0.225 -0.060 -0.060
## 62 CP3 ~~ CP6 2.815 7.227 -0.158 -0.158 -0.055 -0.055
## 55 CP1 ~~ CP6 2.045 5.248 -0.140 -0.140 -0.047 -0.047
## 56 CP2 ~~ CP3 1.038 2.666 -0.061 -0.061 -0.036 -0.036
## 57 CP2 ~~ CP4 0.997 2.560 0.065 0.065 0.032 0.032
## 52 CP1 ~~ CP3 0.512 1.315 -0.053 -0.053 -0.025 -0.025
## 60 CP3 ~~ CP4 0.173 0.445 0.033 0.033 0.013 0.013
## 59 CP2 ~~ CP6 0.024 0.063 -0.012 -0.012 -0.005 -0.005
The author conducted two models for evaluating Cognitive Presense Scale to confirm the hypotheses. The previous model fit indices were as follows: (CFI =0.981, TLI = 0.968, RMSEA = 0.128, SRMR = 0.035, RMR = 0.031). All the aforementioned indices were excellent or good except for RMSEA indix (RMSEA= 0.128). Therefore, the author ran modeification indeices function (modificationindices()) to identify where the local misfits are. I found that item numder five (CP5) has high residual correlated with the items: CP1 and CP2 highly negative, and CP3 as shown above. When looking at item CP5 (which states: I have developed solutions to course problems that can be applied in practice.), I found that the item itself is solution-related item, it does not indicate cognitive presence as defined earlier in the definitios. Therefore, CP5 was removed as a better option than correlating its residual variance with CP1, CP2, and CP3. Then, I run the model again and found that follwing:
Deleting item#5.
grm2PsyntaxCP2 = "
CP =~ CP1 + CP2 + CP3 + CP4 + CP6
CP ~~ 1*CP
CP ~ 0"
grm2PestimatesCP2 = cfa(model = grm2PsyntaxCP2, data = dat, ordered = c("CP1", "CP2", "CP3", "CP4", "CP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 9 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesCP2, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 40 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 5.341 14.339
## Degrees of freedom 5 5
## P-value (Chi-square) 0.376 0.014
## Scaling correction factor 0.375
## Shift parameter 0.081
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 4770.466 2897.905
## Degrees of freedom 10 10
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000 0.997
## Tucker-Lewis Index (TLI) 1.000 0.994
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.010 0.051
## 90 Percent Confidence Interval 0.000 0.054 0.021 0.083
## P-value RMSEA <= 0.05 0.926 0.417
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.017 0.017
##
## Weighted Root Mean Square Residual:
##
## WRMR 0.422 0.422
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP =~
## CP1 1.247 0.084 14.819 0.000 1.247 0.780
## CP2 0.722 0.047 15.501 0.000 0.722 0.585
## CP3 0.946 0.060 15.720 0.000 0.946 0.687
## CP4 1.505 0.091 16.617 0.000 1.505 0.833
## CP6 1.377 0.083 16.537 0.000 1.377 0.809
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP 0.000 0.000 0.000
## .CP1 0.000 0.000 0.000
## .CP2 0.000 0.000 0.000
## .CP3 0.000 0.000 0.000
## .CP4 0.000 0.000 0.000
## .CP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP1|t1 -3.447 0.199 -17.287 0.000 -3.447 -2.157
## CP1|t2 -2.168 0.120 -18.106 0.000 -2.168 -1.357
## CP1|t3 -1.376 0.099 -13.957 0.000 -1.376 -0.861
## CP1|t4 1.174 0.088 13.316 0.000 1.174 0.735
## CP2|t1 -2.167 0.098 -22.072 0.000 -2.167 -1.757
## CP2|t2 -1.194 0.069 -17.327 0.000 -1.194 -0.968
## CP2|t3 -0.302 0.059 -5.102 0.000 -0.302 -0.245
## CP2|t4 1.127 0.067 16.835 0.000 1.127 0.913
## CP3|t1 -2.722 0.141 -19.309 0.000 -2.722 -1.978
## CP3|t2 -1.831 0.093 -19.788 0.000 -1.831 -1.330
## CP3|t3 -1.005 0.074 -13.592 0.000 -1.005 -0.730
## CP3|t4 0.805 0.069 11.686 0.000 0.805 0.585
## CP4|t1 -4.122 0.273 -15.071 0.000 -4.122 -2.281
## CP4|t2 -2.718 0.147 -18.549 0.000 -2.718 -1.504
## CP4|t3 -1.483 0.107 -13.899 0.000 -1.483 -0.821
## CP4|t4 1.213 0.092 13.132 0.000 1.213 0.671
## CP6|t1 -3.671 0.213 -17.235 0.000 -3.671 -2.157
## CP6|t2 -2.453 0.129 -19.022 0.000 -2.453 -1.441
## CP6|t3 -1.422 0.100 -14.165 0.000 -1.422 -0.836
## CP6|t4 1.203 0.089 13.593 0.000 1.203 0.707
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP 1.000 1.000 1.000
## .CP1 1.000 1.000 0.391
## .CP2 1.000 1.000 0.657
## .CP3 1.000 1.000 0.528
## .CP4 1.000 1.000 0.306
## .CP6 1.000 1.000 0.345
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## CP1 0.626 0.626 1.000
## CP2 0.811 0.811 1.000
## CP3 0.727 0.727 1.000
## CP4 0.553 0.553 1.000
## CP6 0.587 0.587 1.000
##
## R-Square:
## Estimate
## CP1 0.609
## CP2 0.343
## CP3 0.472
## CP4 0.694
## CP6 0.655
fitmeasures(grm2PestimatesCP2)
## npar fmin
## 25.000 0.004
## chisq df
## 5.341 5.000
## pvalue chisq.scaled
## 0.376 14.339
## df.scaled pvalue.scaled
## 5.000 0.014
## chisq.scaling.factor baseline.chisq
## 0.375 4770.466
## baseline.df baseline.pvalue
## 10.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 2897.905 10.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 1.648
## cfi tli
## 1.000 1.000
## nnfi rfi
## 1.000 0.998
## nfi pnfi
## 0.999 0.499
## ifi rni
## 1.000 1.000
## cfi.scaled tli.scaled
## 0.997 0.994
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.994 NA
## rfi.scaled nfi.scaled
## 0.990 0.995
## ifi.scaled rni.scaled
## 0.995 0.998
## rni.robust rmsea
## NA 0.010
## rmsea.ci.lower rmsea.ci.upper
## 0.000 0.054
## rmsea.pvalue rmsea.scaled
## 0.926 0.051
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.021 0.083
## rmsea.pvalue.scaled rmsea.robust
## 0.417 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.015
## rmr_nomean srmr
## 0.017 0.017
## srmr_bentler srmr_bentler_nomean
## 0.015 0.017
## srmr_bollen srmr_bollen_nomean
## 0.015 0.017
## srmr_mplus srmr_mplus_nomean
## 0.015 0.017
## cn_05 cn_01
## 1468.467 2000.784
## gfi agfi
## 0.999 0.997
## pgfi mfi
## 0.167 1.000
resid(object = grm2PestimatesCP2)
## $type
## [1] "raw"
##
## $cov
## CP1 CP2 CP3 CP4 CP6
## CP1 0.000
## CP2 0.028 0.000
## CP3 -0.028 -0.036 0.000
## CP4 0.008 -0.013 0.011 0.000
## CP6 -0.014 0.007 0.025 -0.010 0.000
##
## $mean
## CP1 CP2 CP3 CP4 CP6
## 0 0 0 0 0
##
## $th
## CP1|t1 CP1|t2 CP1|t3 CP1|t4 CP2|t1
## 6.565318e-07 -1.555063e-07 1.045697e-07 2.356734e-07 1.364416e-08
## CP2|t2 CP2|t3 CP2|t4 CP3|t1 CP3|t2
## 3.082113e-07 3.778425e-08 1.466072e-07 2.655635e-07 -1.670552e-07
## CP3|t3 CP3|t4 CP4|t1 CP4|t2 CP4|t3
## 1.063476e-07 1.236142e-08 1.606310e-07 -1.977120e-07 -4.881023e-07
## CP4|t4 CP6|t1 CP6|t2 CP6|t3 CP6|t4
## -2.693141e-07 1.132862e-07 -4.301359e-07 3.785124e-07 -1.525117e-07
Correlation matrix for Cognitive Presence Items
library(knitr)
CP_cor_table <- residuals(grm2PestimatesCP2, type = "cor")$cor
CP_cor_table[upper.tri(CP_cor_table)] <- NA
diag(CP_cor_table) <- NA
kable(CP_cor_table, digits=2)
CP1 | CP2 | CP3 | CP4 | CP6 | |
---|---|---|---|---|---|
CP1 | NA | NA | NA | NA | NA |
CP2 | 0.03 | NA | NA | NA | NA |
CP3 | -0.03 | -0.04 | NA | NA | NA |
CP4 | 0.01 | -0.01 | 0.01 | NA | NA |
CP6 | -0.01 | 0.01 | 0.03 | -0.01 | NA |
After running the model again, the model fits well as follows with good fit indices: (CFI =0.997, TLI = 0.994, RMSEA = 0.051, SRMR = 0.017, RMR = 0.015). The cognitive scale has been evaluated and all the fit indices are good.
Below are the statistics for the items of the Cognitive Presence Scale:
library (knitr)
library(dplyr)
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:reshape2':
##
## smiths
parameterEstimates(grm2PestimatesCP2, standardized=TRUE) %>%
filter(op == "=~") %>%
select('Latent Factor'=lhs, Indicator=rhs, B=est, SE=se, Z=z, 'p-value'=pvalue, Beta=std.all) %>%
kable(digits = 3, format="pandoc", caption="Factor Loadings")
Latent Factor | Indicator | B | SE | Z | p-value | Beta |
---|---|---|---|---|---|---|
CP | CP1 | 1.247 | 0.084 | 14.819 | 0 | 0.780 |
CP | CP2 | 0.722 | 0.047 | 15.501 | 0 | 0.585 |
CP | CP3 | 0.946 | 0.060 | 15.720 | 0 | 0.687 |
CP | CP4 | 1.505 | 0.091 | 16.617 | 0 | 0.833 |
CP | CP6 | 1.377 | 0.083 | 16.537 | 0 | 0.809 |
{r} #anova(grm2PestimatesCP1, grm2PestimatesCP2) #
Plotting Cognitive Presence Scale items
lavaanCatItemPlot = function(lavObject, varname, sds = 3){
output = inspect(object = lavObject, what = "est")
if (!varname %in% rownames(output$lambda)) stop(paste(varname, "not found in lavaan object"))
if (dim(output$lambda)[2]>1) stop("plots only given for one factor models")
itemloading = output$lambda[which(rownames(output$lambda) == varname),1]
itemthresholds = output$tau[grep(pattern = varname, x = rownames(output$tau))]
factorname = colnames(output$lambda)
factormean = output$alpha[which(rownames(output$alpha) == factorname)]
factorvar = output$psi[which(rownames(output$psi) == factorname)]
factormin = factormean - 3*sqrt(factorvar)
factormax = factormean + 3*sqrt(factorvar)
factorX = seq(factormin, factormax, .01)
itemloc = which(lavObject@Data@ov$name == varname)
itemlevels = unlist(strsplit(x = lavObject@Data@ov$lnam[itemloc], split = "\\|"))
if (length(itemthresholds)>1){
plotdata = NULL
plotdata2 = NULL
itemY = NULL
itemY2 = NULL
itemX = NULL
itemText = NULL
for (level in 1:length(itemthresholds)){
itemY = pnorm(q = -1*itemthresholds[level] + itemloading*factorX)
itemY2 = cbind(itemY2, pnorm(q = -1*itemthresholds[level] + itemloading*factorX))
itemText = paste0("P(", varname, " > ", itemlevels[level], ")")
itemText2 = paste0("P(", varname, " = ", itemlevels[level], ")")
plotdata = rbind(plotdata, data.frame(factor = factorX, prob = itemY, plot = itemText))
if (level == 1){
plotdata2 = data.frame(factor = factorX, plot = itemText2, prob = matrix(1, nrow = dim(itemY2)[1], ncol=1) - itemY2[,level])
} else if (level == length(itemthresholds)){
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level]))
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = paste0("P(", varname, " = ", itemlevels[level+1], ")"), prob = itemY2[,level]))
} else {
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level]))
}
}
names(plotdata) = c(factorname , "Probability", "Cumulative")
ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Cumulative")) + geom_line(size = 2)
names(plotdata2) = c(factorname, "Response", "Probability")
ggplot(data = plotdata2, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2)
} else {
itemY = pnorm(q = -1*itemthresholds[1] + itemloading*factorX)
itemText2 = paste0("P(", varname, " = ", itemlevels[1], ")")
plotdata = data.frame(factor = factorX, prob = itemY, plot = itemText2)
names(plotdata) = c(factorname , "Probability", "Response")
ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2)
}
}
lavaanCatItemPlot(lavObject = grm2PestimatesCP2, varname = "CP1", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesCP2, varname = "CP2", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesCP2, varname = "CP3", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesCP2, varname = "CP4", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesCP2, varname = "CP6", sds = 3)
Cognitive Presence Factor Score:
factor_scoresCP <- predict(grm2PestimatesCP2)
CP<- factor_scoresCP[,]
ggplot() +
geom_density(aes(x = CP), color = "blue", alpha = 0.45, fill ="blue") +
xlim(-3,3) +
theme(panel.background = element_blank())+
ggtitle("Cognitive Presence Factor Distribution")+
ylab("Probability")+
xlab("theta")
———- ####Question2: Scale #2: Teaching Presence Scale: ———-
library("MVN")
# Pull out the items for Teaching Presence Scale:
x_vars <- dat[,paste("TP", c(1,2,3,4,5,6), sep="")]
uniPlot(x_vars, type = "histogram")
grm2PsyntaxTP1 = "
TP =~ TP1 + TP2 + TP3 + TP4 + TP5 + TP6;
TP ~ 1*TP
TP ~ 0"
grm2PestimatesTP1 = cfa(model = grm2PsyntaxTP1, data = dat, ordered = c("TP1", "TP2", "TP3", "TP4", "TP5", "TP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 15 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesTP1, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 42 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 41.616 104.894
## Degrees of freedom 9 9
## P-value (Chi-square) 0.000 0.000
## Scaling correction factor 0.400
## Shift parameter 0.809
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 11948.645 5978.057
## Degrees of freedom 15 15
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.997 0.984
## Tucker-Lewis Index (TLI) 0.995 0.973
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.072 0.123
## 90 Percent Confidence Interval 0.050 0.094 0.102 0.144
## P-value RMSEA <= 0.05 0.047 0.000
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.034 0.034
##
## Weighted Root Mean Square Residual:
##
## WRMR 1.033 1.033
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP =~
## TP1 1.266 0.074 17.046 0.000 1.266 0.785
## TP2 1.630 0.086 18.950 0.000 1.630 0.852
## TP3 1.499 0.083 18.062 0.000 1.499 0.832
## TP4 1.439 0.078 18.466 0.000 1.439 0.821
## TP5 1.243 0.069 18.030 0.000 1.243 0.779
## TP6 1.037 0.060 17.192 0.000 1.037 0.720
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP ~
## TP 1.000 1.000 1.000
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .TP 0.000 0.000 0.000
## .TP1 0.000 0.000 0.000
## .TP2 0.000 0.000 0.000
## .TP3 0.000 0.000 0.000
## .TP4 0.000 0.000 0.000
## .TP5 0.000 0.000 0.000
## .TP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP1|t1 -3.960 0.232 -17.060 0.000 -3.960 -2.455
## TP1|t2 -2.918 0.148 -19.694 0.000 -2.918 -1.809
## TP1|t3 -2.028 0.113 -17.962 0.000 -2.028 -1.257
## TP1|t4 0.672 0.078 8.656 0.000 0.672 0.417
## TP2|t1 -4.361 0.236 -18.449 0.000 -4.361 -2.281
## TP2|t2 -2.815 0.130 -21.605 0.000 -2.815 -1.472
## TP2|t3 -1.598 0.109 -14.638 0.000 -1.598 -0.836
## TP2|t4 0.977 0.092 10.671 0.000 0.977 0.511
## TP3|t1 -4.566 0.288 -15.843 0.000 -4.566 -2.534
## TP3|t2 -3.136 0.162 -19.417 0.000 -3.136 -1.740
## TP3|t3 -1.818 0.114 -15.976 0.000 -1.818 -1.009
## TP3|t4 0.863 0.087 9.965 0.000 0.863 0.479
## TP4|t1 -3.918 0.222 -17.611 0.000 -3.918 -2.235
## TP4|t2 -2.757 0.133 -20.742 0.000 -2.757 -1.573
## TP4|t3 -1.231 0.092 -13.362 0.000 -1.231 -0.702
## TP4|t4 1.200 0.088 13.559 0.000 1.200 0.685
## TP5|t1 -3.810 0.231 -16.492 0.000 -3.810 -2.388
## TP5|t2 -2.253 0.107 -21.018 0.000 -2.253 -1.412
## TP5|t3 -1.128 0.086 -13.106 0.000 -1.128 -0.707
## TP5|t4 1.325 0.085 15.582 0.000 1.325 0.831
## TP6|t1 -2.781 0.140 -19.904 0.000 -2.781 -1.930
## TP6|t2 -1.892 0.093 -20.315 0.000 -1.892 -1.314
## TP6|t3 -1.025 0.076 -13.471 0.000 -1.025 -0.712
## TP6|t4 1.025 0.074 13.935 0.000 1.025 0.712
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .TP1 1.000 1.000 0.384
## .TP2 1.000 1.000 0.273
## .TP3 1.000 1.000 0.308
## .TP4 1.000 1.000 0.326
## .TP5 1.000 1.000 0.393
## .TP6 1.000 1.000 0.482
## .TP 1.000 1.000 1.000
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP1 0.620 0.620 1.000
## TP2 0.523 0.523 1.000
## TP3 0.555 0.555 1.000
## TP4 0.571 0.571 1.000
## TP5 0.627 0.627 1.000
## TP6 0.694 0.694 1.000
##
## R-Square:
## Estimate
## TP1 0.616
## TP2 0.727
## TP3 0.692
## TP4 0.674
## TP5 0.607
## TP6 0.518
## TP 0.000
fitmeasures(grm2PestimatesTP1)
## npar fmin
## 30.000 0.029
## chisq df
## 41.616 9.000
## pvalue chisq.scaled
## 0.000 104.894
## df.scaled pvalue.scaled
## 9.000 0.000
## chisq.scaling.factor baseline.chisq
## 0.400 11948.645
## baseline.df baseline.pvalue
## 15.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 5978.057 15.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 2.001
## cfi tli
## 0.997 0.995
## nnfi rfi
## 0.995 0.994
## nfi pnfi
## 0.997 0.598
## ifi rni
## 0.997 0.997
## cfi.scaled tli.scaled
## 0.984 0.973
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.973 NA
## rfi.scaled nfi.scaled
## 0.971 0.982
## ifi.scaled rni.scaled
## 0.982 0.992
## rni.robust rmsea
## NA 0.072
## rmsea.ci.lower rmsea.ci.upper
## 0.050 0.094
## rmsea.pvalue rmsea.scaled
## 0.047 0.123
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.102 0.144
## rmsea.pvalue.scaled rmsea.robust
## 0.000 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.030
## rmr_nomean srmr
## 0.034 0.034
## srmr_bentler srmr_bentler_nomean
## 0.030 0.034
## srmr_bollen srmr_bollen_nomean
## 0.030 0.034
## srmr_mplus srmr_mplus_nomean
## 0.030 0.034
## cn_05 cn_01
## 288.837 369.596
## gfi agfi
## 0.998 0.990
## pgfi mfi
## 0.230 0.977
modificationindices(grm2PestimatesTP1, sort. = TRUE)
## lhs op rhs mi mi.scaled epc sepc.lv sepc.all sepc.nox
## 66 TP5 ~~ TP6 14.309 35.788 0.254 0.254 0.110 0.110
## 53 TP1 ~~ TP3 13.088 32.733 0.302 0.302 0.104 0.104
## 55 TP1 ~~ TP5 8.497 21.252 -0.242 -0.242 -0.094 -0.094
## 54 TP1 ~~ TP4 6.941 17.361 -0.235 -0.235 -0.083 -0.083
## 52 TP1 ~~ TP2 6.430 16.083 0.223 0.223 0.072 0.072
## 60 TP2 ~~ TP6 6.399 16.005 -0.233 -0.233 -0.085 -0.085
## 56 TP1 ~~ TP6 3.685 9.217 -0.149 -0.149 -0.064 -0.064
## 58 TP2 ~~ TP4 2.330 5.827 0.142 0.142 0.042 0.042
## 57 TP2 ~~ TP3 2.263 5.660 -0.148 -0.148 -0.043 -0.043
## 62 TP3 ~~ TP5 2.061 5.156 -0.124 -0.124 -0.043 -0.043
## 64 TP4 ~~ TP5 1.613 4.035 0.103 0.103 0.037 0.037
## 61 TP3 ~~ TP4 0.496 1.239 -0.065 -0.065 -0.021 -0.021
## 59 TP2 ~~ TP5 0.421 1.053 -0.059 -0.059 -0.019 -0.019
## 65 TP4 ~~ TP6 0.041 0.104 0.017 0.017 0.007 0.007
## 63 TP3 ~~ TP6 0.019 0.048 0.012 0.012 0.005 0.005
The author conducted two models for evaluating Teaching Presense Scale to confirm the hypotheses. The previous model fit indices were as follows: (CFI = 0.984, TLI = 0.973, RMSEA = 0.123 , SRMR = 0.034, RMR = 0.030 ). All the aforementioned indices were also excellent or good for this scale except for RMSEA indix (RMSEA= 0.123). Therefore, the author ran modeification indeices function to identify where the local misfits are. I found that item numder 1 (TP1) was highly correlated with items: TP2, TP3,TP4, and TP5. When looking at item number 1 (The instructor clearly communicated important course goals.), I found that the item itself is about course content rather than about teaching, it does not indicate cognitive presence based on the definition mentioned earlier. Therefore, TP1 was removed. Then, I run the model again and found the follwing:
Deleting item#1:
grm2PsyntaxTP2 = "
TP =~ TP2 + TP3 + TP4 + TP5 + TP6;
TP ~ 1*TP
TP ~ 0
TP5 ~~ TP6"
grm2PestimatesTP2 = cfa(model = grm2PsyntaxTP2, data = dat, ordered = c("TP2", "TP3", "TP4", "TP5", "TP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 10 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesTP2, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 47 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 3.855 11.244
## Degrees of freedom 4 4
## P-value (Chi-square) 0.426 0.024
## Scaling correction factor 0.347
## Shift parameter 0.146
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 8336.915 4973.481
## Degrees of freedom 10 10
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000 0.999
## Tucker-Lewis Index (TLI) 1.000 0.996
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000 0.051
## 90 Percent Confidence Interval 0.000 0.056 0.017 0.087
## P-value RMSEA <= 0.05 0.915 0.427
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.013 0.013
##
## Weighted Root Mean Square Residual:
##
## WRMR 0.358 0.358
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP =~
## TP2 1.554 0.089 17.466 0.000 1.554 0.841
## TP3 1.398 0.083 16.895 0.000 1.398 0.813
## TP4 1.588 0.094 16.857 0.000 1.588 0.846
## TP5 1.225 0.073 16.839 0.000 1.225 0.775
## TP6 0.983 0.064 15.433 0.000 0.983 0.701
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP ~
## TP 1.000 1.000 1.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .TP5 ~~
## .TP6 0.192 0.042 4.575 0.000 0.192 0.192
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .TP 0.000 0.000 0.000
## .TP2 0.000 0.000 0.000
## .TP3 0.000 0.000 0.000
## .TP4 0.000 0.000 0.000
## .TP5 0.000 0.000 0.000
## .TP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP2|t1 -4.214 0.230 -18.337 0.000 -4.214 -2.281
## TP2|t2 -2.720 0.134 -20.307 0.000 -2.720 -1.472
## TP2|t3 -1.544 0.108 -14.255 0.000 -1.544 -0.836
## TP2|t4 0.944 0.090 10.460 0.000 0.944 0.511
## TP3|t1 -4.355 0.277 -15.714 0.000 -4.355 -2.534
## TP3|t2 -2.991 0.156 -19.186 0.000 -2.991 -1.740
## TP3|t3 -1.734 0.110 -15.782 0.000 -1.734 -1.009
## TP3|t4 0.824 0.084 9.841 0.000 0.824 0.479
## TP4|t1 -4.195 0.256 -16.375 0.000 -4.195 -2.235
## TP4|t2 -2.953 0.153 -19.288 0.000 -2.953 -1.573
## TP4|t3 -1.318 0.102 -12.946 0.000 -1.318 -0.702
## TP4|t4 1.285 0.098 13.080 0.000 1.285 0.685
## TP5|t1 -3.777 0.239 -15.770 0.000 -3.777 -2.388
## TP5|t2 -2.233 0.109 -20.418 0.000 -2.233 -1.412
## TP5|t3 -1.118 0.086 -13.000 0.000 -1.118 -0.707
## TP5|t4 1.313 0.086 15.274 0.000 1.313 0.831
## TP6|t1 -2.707 0.143 -18.991 0.000 -2.707 -1.930
## TP6|t2 -1.842 0.094 -19.517 0.000 -1.842 -1.314
## TP6|t3 -0.998 0.075 -13.343 0.000 -0.998 -0.712
## TP6|t4 0.998 0.073 13.668 0.000 0.998 0.712
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .TP2 1.000 1.000 0.293
## .TP3 1.000 1.000 0.338
## .TP4 1.000 1.000 0.284
## .TP5 1.000 1.000 0.400
## .TP6 1.000 1.000 0.509
## .TP 1.000 1.000 1.000
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## TP2 0.541 0.541 1.000
## TP3 0.582 0.582 1.000
## TP4 0.533 0.533 1.000
## TP5 0.632 0.632 1.000
## TP6 0.713 0.713 1.000
##
## R-Square:
## Estimate
## TP2 0.707
## TP3 0.662
## TP4 0.716
## TP5 0.600
## TP6 0.491
## TP 0.000
modificationindices(grm2PestimatesTP2, sort. = TRUE)
## lhs op rhs mi mi.scaled epc sepc.lv sepc.all sepc.nox
## 48 TP2 ~~ TP6 2.777 7.995 -0.162 -0.162 -0.063 -0.063
## 51 TP3 ~~ TP6 2.372 6.829 0.135 0.135 0.056 0.056
## 49 TP3 ~~ TP4 1.490 4.290 -0.136 -0.136 -0.042 -0.042
## 46 TP2 ~~ TP4 0.513 1.475 0.086 0.086 0.025 0.025
## 50 TP3 ~~ TP5 0.247 0.712 -0.045 -0.045 -0.017 -0.017
## 45 TP2 ~~ TP3 0.215 0.618 0.049 0.049 0.015 0.015
## 52 TP4 ~~ TP5 0.152 0.438 0.039 0.039 0.013 0.013
## 53 TP4 ~~ TP6 0.015 0.044 0.012 0.012 0.005 0.005
## 47 TP2 ~~ TP5 0.009 0.027 0.010 0.010 0.003 0.003
resid(object = grm2PestimatesTP2)
## $type
## [1] "raw"
##
## $cov
## TP2 TP3 TP4 TP5 TP6
## TP2 0.000
## TP3 0.005 0.000
## TP4 0.007 -0.016 0.000
## TP5 0.001 -0.008 0.006 0.000
## TP6 -0.034 0.032 0.002 0.000 0.000
##
## $mean
## TP2 TP3 TP4 TP5 TP6
## 0 0 0 0 0
##
## $th
## TP2|t1 TP2|t2 TP2|t3 TP2|t4 TP3|t1
## 3.038509e-07 1.499811e-07 -1.380040e-07 -8.308856e-08 -6.696863e-07
## TP3|t2 TP3|t3 TP3|t4 TP4|t1 TP4|t2
## 2.962330e-08 1.841774e-07 -4.783092e-08 4.011755e-07 8.274558e-08
## TP4|t3 TP4|t4 TP5|t1 TP5|t2 TP5|t3
## -7.356678e-08 6.074634e-08 -1.845246e-07 1.373320e-07 -4.880453e-08
## TP5|t4 TP6|t1 TP6|t2 TP6|t3 TP6|t4
## -1.616310e-07 2.666616e-08 -2.261756e-07 8.201930e-08 -8.201930e-08
Correlation matrix for Teaching Presence Items:
TP_cor_table <- residuals(grm2PestimatesTP2, type = "cor")$cor
TP_cor_table[upper.tri(TP_cor_table)] <- NA
diag(TP_cor_table) <- NA
kable(TP_cor_table, digits=2)
TP2 | TP3 | TP4 | TP5 | TP6 | |
---|---|---|---|---|---|
TP2 | NA | NA | NA | NA | NA |
TP3 | 0.01 | NA | NA | NA | NA |
TP4 | 0.01 | -0.02 | NA | NA | NA |
TP5 | 0.00 | -0.01 | 0.01 | NA | NA |
TP6 | -0.03 | 0.03 | 0.00 | 0 | NA |
Below are the items statistics of the Cognitive Presence Scale:
library (knitr)
library(dplyr)
library(tidyr)
parameterEstimates(grm2PestimatesTP2, standardized=TRUE) %>%
filter(op == "=~") %>%
select('Latent Factor'=lhs, Indicator=rhs, B=est, SE=se, Z=z, 'p-value'=pvalue, Beta=std.all) %>%
kable(digits = 3, format="pandoc", caption="Factor Loadings")
Latent Factor | Indicator | B | SE | Z | p-value | Beta |
---|---|---|---|---|---|---|
TP | TP2 | 1.554 | 0.089 | 17.466 | 0 | 0.841 |
TP | TP3 | 1.398 | 0.083 | 16.895 | 0 | 0.813 |
TP | TP4 | 1.588 | 0.094 | 16.857 | 0 | 0.846 |
TP | TP5 | 1.225 | 0.073 | 16.839 | 0 | 0.775 |
TP | TP6 | 0.983 | 0.064 | 15.433 | 0 | 0.701 |
{r} #anova(grm2PestimatesTP1, grm2PestimatesTP2) #
Plotting Social Teaching Scale items:
lavaanCatItemPlot = function(lavObject, varname, sds = 3){
output = inspect(object = lavObject, what = "est")
if (!varname %in% rownames(output$lambda)) stop(paste(varname, "not found in lavaan object"))
if (dim(output$lambda)[2]>1) stop("plots only given for one factor models")
itemloading = output$lambda[which(rownames(output$lambda) == varname),1]
itemthresholds = output$tau[grep(pattern = varname, x = rownames(output$tau))]
factorname = colnames(output$lambda)
factormean = output$alpha[which(rownames(output$alpha) == factorname)]
factorvar = output$psi[which(rownames(output$psi) == factorname)]
factormin = factormean - 3*sqrt(factorvar)
factormax = factormean + 3*sqrt(factorvar)
factorX = seq(factormin, factormax, .01)
itemloc = which(lavObject@Data@ov$name == varname)
itemlevels = unlist(strsplit(x = lavObject@Data@ov$lnam[itemloc], split = "\\|"))
if (length(itemthresholds)>1){
plotdata = NULL
plotdata2 = NULL
itemY = NULL
itemY2 = NULL
itemX = NULL
itemText = NULL
for (level in 1:length(itemthresholds)){
itemY = pnorm(q = -1*itemthresholds[level] + itemloading*factorX)
itemY2 = cbind(itemY2, pnorm(q = -1*itemthresholds[level] + itemloading*factorX))
itemText = paste0("P(", varname, " > ", itemlevels[level], ")")
itemText2 = paste0("P(", varname, " = ", itemlevels[level], ")")
plotdata = rbind(plotdata, data.frame(factor = factorX, prob = itemY, plot = itemText))
if (level == 1){
plotdata2 = data.frame(factor = factorX, plot = itemText2, prob = matrix(1, nrow = dim(itemY2)[1], ncol=1) - itemY2[,level])
} else if (level == length(itemthresholds)){
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level]))
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = paste0("P(", varname, " = ", itemlevels[level+1], ")"), prob = itemY2[,level]))
} else {
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level]))
}
}
names(plotdata) = c(factorname , "Probability", "Cumulative")
ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Cumulative")) + geom_line(size = 2)
names(plotdata2) = c(factorname, "Response", "Probability")
ggplot(data = plotdata2, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2)
} else {
itemY = pnorm(q = -1*itemthresholds[1] + itemloading*factorX)
itemText2 = paste0("P(", varname, " = ", itemlevels[1], ")")
plotdata = data.frame(factor = factorX, prob = itemY, plot = itemText2)
names(plotdata) = c(factorname , "Probability", "Response")
ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2)
}
}
lavaanCatItemPlot(lavObject = grm2PestimatesTP2, varname = "TP2", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesTP2, varname = "TP3", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesTP2, varname = "TP4", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesTP2, varname = "TP5", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesTP2, varname = "TP6", sds = 3)
Teaching Presence Factor Score:
factor_scoresTP <- predict(grm2PestimatesTP2)
TP<- factor_scoresTP[,]
ggplot() +
geom_density(aes(x = TP), color = "brown", alpha = 0.45, fill ="lightblue") +
xlim(-3,3) +
theme(panel.background = element_blank()) +
ggtitle("Teaching Presence Factor Distribution")+
ylab("Probability")+
xlab("theta")
———- ####Question2: Scale #3: Social Presence:———-
library("MVN")
# Pull out the items for Social Presence Scale:
x_vars <- dat[,paste("SP", c(1,2,3,4,5,6), sep="")]
uniPlot(x_vars, type = "histogram")
grm2PsyntaxSP1 = "
SP =~ SP1 + SP2 + SP3 + SP4 + SP5 + SP6
SP ~~ 1*SP
SP ~ 0"
grm2PestimatesSP1 = cfa(model = grm2PsyntaxSP1, data = dat, ordered = c("SP1", "SP2", "SP3", "SP4", "SP5", "SP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 14 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesSP1, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 39 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 111.274 254.457
## Degrees of freedom 9 9
## P-value (Chi-square) 0.000 0.000
## Scaling correction factor 0.439
## Shift parameter 0.949
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 7887.904 4440.843
## Degrees of freedom 15 15
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.987 0.945
## Tucker-Lewis Index (TLI) 0.978 0.908
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.127 0.196
## 90 Percent Confidence Interval 0.106 0.148 0.176 0.217
## P-value RMSEA <= 0.05 0.000 0.000
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.057 0.057
##
## Weighted Root Mean Square Residual:
##
## WRMR 1.689 1.689
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP =~
## SP1 1.418 0.090 15.800 0.000 1.418 0.817
## SP2 1.620 0.101 15.970 0.000 1.620 0.851
## SP3 0.920 0.057 16.221 0.000 0.920 0.677
## SP4 0.858 0.055 15.565 0.000 0.858 0.651
## SP5 1.313 0.075 17.507 0.000 1.313 0.795
## SP6 0.953 0.057 16.814 0.000 0.953 0.690
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 0.000 0.000 0.000
## .SP1 0.000 0.000 0.000
## .SP2 0.000 0.000 0.000
## .SP3 0.000 0.000 0.000
## .SP4 0.000 0.000 0.000
## .SP5 0.000 0.000 0.000
## .SP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP1|t1 -4.568 0.306 -14.951 0.000 -4.568 -2.633
## SP1|t2 -3.019 0.170 -17.785 0.000 -3.019 -1.740
## SP1|t3 -2.027 0.130 -15.628 0.000 -2.027 -1.169
## SP1|t4 0.643 0.083 7.725 0.000 0.643 0.371
## SP2|t1 -4.546 0.290 -15.654 0.000 -4.546 -2.388
## SP2|t2 -3.066 0.175 -17.514 0.000 -3.066 -1.611
## SP2|t3 -1.876 0.129 -14.520 0.000 -1.876 -0.985
## SP2|t4 0.620 0.087 7.100 0.000 0.620 0.326
## SP3|t1 -3.099 0.174 -17.838 0.000 -3.099 -2.281
## SP3|t2 -2.121 0.103 -20.612 0.000 -2.121 -1.561
## SP3|t3 -1.043 0.074 -14.121 0.000 -1.043 -0.767
## SP3|t4 0.888 0.068 12.986 0.000 0.888 0.654
## SP4|t1 -2.796 0.147 -18.992 0.000 -2.796 -2.122
## SP4|t2 -1.616 0.083 -19.395 0.000 -1.616 -1.226
## SP4|t3 -0.595 0.066 -9.017 0.000 -0.595 -0.452
## SP4|t4 1.148 0.072 15.935 0.000 1.148 0.871
## SP5|t1 -3.847 0.228 -16.909 0.000 -3.847 -2.331
## SP5|t2 -2.659 0.131 -20.318 0.000 -2.659 -1.611
## SP5|t3 -1.159 0.090 -12.837 0.000 -1.159 -0.702
## SP5|t4 1.144 0.084 13.635 0.000 1.144 0.693
## SP6|t1 -2.699 0.137 -19.703 0.000 -2.699 -1.953
## SP6|t2 -1.521 0.082 -18.524 0.000 -1.521 -1.101
## SP6|t3 -0.528 0.067 -7.838 0.000 -0.528 -0.382
## SP6|t4 1.008 0.071 14.280 0.000 1.008 0.730
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 1.000 1.000 1.000
## .SP1 1.000 1.000 0.332
## .SP2 1.000 1.000 0.276
## .SP3 1.000 1.000 0.542
## .SP4 1.000 1.000 0.576
## .SP5 1.000 1.000 0.367
## .SP6 1.000 1.000 0.524
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP1 0.576 0.576 1.000
## SP2 0.525 0.525 1.000
## SP3 0.736 0.736 1.000
## SP4 0.759 0.759 1.000
## SP5 0.606 0.606 1.000
## SP6 0.724 0.724 1.000
##
## R-Square:
## Estimate
## SP1 0.668
## SP2 0.724
## SP3 0.458
## SP4 0.424
## SP5 0.633
## SP6 0.476
fitmeasures(grm2PestimatesSP1)
## npar fmin
## 30.000 0.078
## chisq df
## 111.274 9.000
## pvalue chisq.scaled
## 0.000 254.457
## df.scaled pvalue.scaled
## 9.000 0.000
## chisq.scaling.factor baseline.chisq
## 0.439 7887.904
## baseline.df baseline.pvalue
## 15.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 4440.843 15.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 1.779
## cfi tli
## 0.987 0.978
## nnfi rfi
## 0.978 0.976
## nfi pnfi
## 0.986 0.592
## ifi rni
## 0.987 0.987
## cfi.scaled tli.scaled
## 0.945 0.908
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.908 NA
## rfi.scaled nfi.scaled
## 0.905 0.943
## ifi.scaled rni.scaled
## 0.943 0.969
## rni.robust rmsea
## NA 0.127
## rmsea.ci.lower rmsea.ci.upper
## 0.106 0.148
## rmsea.pvalue rmsea.scaled
## 0.000 0.196
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.176 0.217
## rmsea.pvalue.scaled rmsea.robust
## 0.000 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.050
## rmr_nomean srmr
## 0.057 0.057
## srmr_bentler srmr_bentler_nomean
## 0.050 0.057
## srmr_bollen srmr_bollen_nomean
## 0.050 0.057
## srmr_mplus srmr_mplus_nomean
## 0.050 0.057
## cn_05 cn_01
## 108.650 138.853
## gfi agfi
## 0.992 0.966
## pgfi mfi
## 0.229 0.930
modificationindices(grm2PestimatesSP1)
## lhs op rhs mi mi.scaled epc sepc.lv sepc.all sepc.nox
## 51 SP1 ~~ SP2 77.091 175.631 0.921 0.921 0.279 0.279
## 52 SP1 ~~ SP3 1.976 4.501 -0.114 -0.114 -0.049 -0.049
## 53 SP1 ~~ SP4 2.089 4.759 -0.118 -0.118 -0.051 -0.051
## 54 SP1 ~~ SP5 17.009 38.751 -0.412 -0.412 -0.144 -0.144
## 55 SP1 ~~ SP6 21.999 50.119 -0.417 -0.417 -0.174 -0.174
## 56 SP2 ~~ SP3 0.048 0.110 0.019 0.019 0.007 0.007
## 57 SP2 ~~ SP4 6.083 13.858 -0.229 -0.229 -0.091 -0.091
## 58 SP2 ~~ SP5 32.906 74.967 -0.651 -0.651 -0.207 -0.207
## 59 SP2 ~~ SP6 9.930 22.623 -0.297 -0.297 -0.113 -0.113
## 60 SP3 ~~ SP4 0.874 1.992 -0.059 -0.059 -0.033 -0.033
## 61 SP3 ~~ SP5 0.017 0.040 -0.010 -0.010 -0.004 -0.004
## 62 SP3 ~~ SP6 5.231 11.917 0.141 0.141 0.075 0.075
## 63 SP4 ~~ SP5 26.182 59.649 0.355 0.355 0.163 0.163
## 64 SP4 ~~ SP6 1.011 2.302 -0.064 -0.064 -0.035 -0.035
## 65 SP5 ~~ SP6 33.788 76.976 0.409 0.409 0.179 0.179
The author conducted two models for evaluating Social Presense Scale to confirm the hypotheses. The previous model fit indices were as follows: (CFI = 0.945, TLI = 0.908, RMSEA = 0.196 , SRMR = 0.057, RMR = 0.050). All the aforementioned indices were not good enough for this scale. Therefore, the author ran modeification indeices function to identify where the local misfits are. I found that item numder 1 (SP1) was highly correlated with items: SP2, SP5, and SP6. When looking at item number 1 (I felt comfortable conversing through the online medium.), I found that the item itself asks about the medium/technology rather than about the individuals’ salience in online environments, it does not indicate social appearance based on the definition mentioned earlier. Therefore, SP1 was removed. Then, I run the model again and found the follwing:
grm2PsyntaxSP2 = "
SP =~ SP2 + SP3 + SP4 + SP5 + SP6
SP ~~ 1*SP
SP ~ 0"
grm2PestimatesSP2 = cfa(model = grm2PsyntaxSP2, data = dat, ordered = c("SP2", "SP3", "SP4", "SP5", "SP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 9 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesSP2, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 35 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 27.835 69.175
## Degrees of freedom 5 5
## P-value (Chi-square) 0.000 0.000
## Scaling correction factor 0.403
## Shift parameter 0.136
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 4246.983 2730.416
## Degrees of freedom 10 10
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.995 0.976
## Tucker-Lewis Index (TLI) 0.989 0.953
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.080 0.135
## 90 Percent Confidence Interval 0.053 0.111 0.108 0.164
## P-value RMSEA <= 0.05 0.036 0.000
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.036 0.036
##
## Weighted Root Mean Square Residual:
##
## WRMR 0.963 0.963
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP =~
## SP2 1.088 0.069 15.666 0.000 1.088 0.736
## SP3 0.970 0.063 15.332 0.000 0.970 0.696
## SP4 0.886 0.059 15.054 0.000 0.886 0.663
## SP5 1.562 0.103 15.103 0.000 1.562 0.842
## SP6 1.061 0.064 16.556 0.000 1.061 0.728
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 0.000 0.000 0.000
## .SP2 0.000 0.000 0.000
## .SP3 0.000 0.000 0.000
## .SP4 0.000 0.000 0.000
## .SP5 0.000 0.000 0.000
## .SP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP2|t1 -3.529 0.224 -15.785 0.000 -3.529 -2.388
## SP2|t2 -2.380 0.121 -19.626 0.000 -2.380 -1.611
## SP2|t3 -1.456 0.091 -16.056 0.000 -1.456 -0.985
## SP2|t4 0.481 0.069 7.010 0.000 0.481 0.326
## SP3|t1 -3.177 0.182 -17.500 0.000 -3.177 -2.281
## SP3|t2 -2.175 0.109 -19.968 0.000 -2.175 -1.561
## SP3|t3 -1.069 0.077 -13.917 0.000 -1.069 -0.767
## SP3|t4 0.910 0.071 12.800 0.000 0.910 0.654
## SP4|t1 -2.834 0.150 -18.845 0.000 -2.834 -2.122
## SP4|t2 -1.638 0.085 -19.204 0.000 -1.638 -1.226
## SP4|t3 -0.603 0.067 -8.968 0.000 -0.603 -0.452
## SP4|t4 1.164 0.074 15.658 0.000 1.164 0.871
## SP5|t1 -4.323 0.277 -15.580 0.000 -4.323 -2.331
## SP5|t2 -2.988 0.165 -18.106 0.000 -2.988 -1.611
## SP5|t3 -1.303 0.110 -11.897 0.000 -1.303 -0.702
## SP5|t4 1.286 0.100 12.880 0.000 1.286 0.693
## SP6|t1 -2.848 0.147 -19.343 0.000 -2.848 -1.953
## SP6|t2 -1.605 0.088 -18.219 0.000 -1.605 -1.101
## SP6|t3 -0.557 0.071 -7.807 0.000 -0.557 -0.382
## SP6|t4 1.064 0.075 14.143 0.000 1.064 0.730
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 1.000 1.000 1.000
## .SP2 1.000 1.000 0.458
## .SP3 1.000 1.000 0.515
## .SP4 1.000 1.000 0.560
## .SP5 1.000 1.000 0.291
## .SP6 1.000 1.000 0.470
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP2 0.677 0.677 1.000
## SP3 0.718 0.718 1.000
## SP4 0.749 0.749 1.000
## SP5 0.539 0.539 1.000
## SP6 0.686 0.686 1.000
##
## R-Square:
## Estimate
## SP2 0.542
## SP3 0.485
## SP4 0.440
## SP5 0.709
## SP6 0.530
fitmeasures(grm2PestimatesSP2)
## npar fmin
## 25.000 0.020
## chisq df
## 27.835 5.000
## pvalue chisq.scaled
## 0.000 69.175
## df.scaled pvalue.scaled
## 5.000 0.000
## chisq.scaling.factor baseline.chisq
## 0.403 4246.983
## baseline.df baseline.pvalue
## 10.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 2730.416 10.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 1.557
## cfi tli
## 0.995 0.989
## nnfi rfi
## 0.989 0.987
## nfi pnfi
## 0.993 0.497
## ifi rni
## 0.995 0.995
## cfi.scaled tli.scaled
## 0.976 0.953
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.953 NA
## rfi.scaled nfi.scaled
## 0.949 0.975
## ifi.scaled rni.scaled
## 0.975 0.985
## rni.robust rmsea
## NA 0.080
## rmsea.ci.lower rmsea.ci.upper
## 0.053 0.111
## rmsea.pvalue rmsea.scaled
## 0.036 0.135
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.108 0.164
## rmsea.pvalue.scaled rmsea.robust
## 0.000 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.031
## rmr_nomean srmr
## 0.036 0.036
## srmr_bentler srmr_bentler_nomean
## 0.031 0.036
## srmr_bollen srmr_bollen_nomean
## 0.031 0.036
## srmr_mplus srmr_mplus_nomean
## 0.031 0.036
## cn_05 cn_01
## 282.588 384.733
## gfi agfi
## 0.997 0.982
## pgfi mfi
## 0.166 0.984
modificationindices(grm2PestimatesSP2, sort. = TRUE)
## lhs op rhs mi mi.scaled epc sepc.lv sepc.all sepc.nox
## 43 SP2 ~~ SP3 14.705 36.474 0.281 0.281 0.137 0.137
## 50 SP4 ~~ SP5 12.189 30.232 0.330 0.330 0.133 0.133
## 45 SP2 ~~ SP5 9.319 23.115 -0.347 -0.347 -0.126 -0.126
## 48 SP3 ~~ SP5 8.132 20.171 -0.298 -0.298 -0.116 -0.116
## 51 SP4 ~~ SP6 6.354 15.761 -0.188 -0.188 -0.096 -0.096
## 52 SP5 ~~ SP6 5.264 13.056 0.243 0.243 0.090 0.090
## 47 SP3 ~~ SP4 3.391 8.412 -0.130 -0.130 -0.070 -0.070
## 46 SP2 ~~ SP6 0.815 2.022 -0.075 -0.075 -0.035 -0.035
## 49 SP3 ~~ SP6 0.377 0.936 0.046 0.046 0.023 0.023
## 44 SP2 ~~ SP4 0.058 0.143 0.018 0.018 0.009 0.009
The author conducted two models for evaluating Social Presense Scale to confirm the hypotheses. The previous model fit indices were as follows: (CFI = 0.976, TLI = 0.953, RMSEA = 0.135 , SRMR = 0.036, RMR = 0.031). All of the fit indices are eigher excellent or good except for RMEAS (0.135). Therefore, I ran modificatinon indices function and found that SP2 and SP3 residuals should be correlated. When looking at the items themselves (SP2:I felt comfortable participating in the course discussions; SP3:The instructor helped keep the course participants on task in a way that helped me to learn), we can see that both of these items as about partticipation, which make sense to correlate their residuals. Therefore, SP2 and SP3 residuals were correlated and the mdoel was run again.
grm2PsyntaxSP3 = "
SP =~ SP2 + SP3 + SP4 + SP5 + SP6
SP ~~ 1*SP
SP ~ 0
SP2 ~~ SP3"
grm2PestimatesSP3 = cfa(model = grm2PsyntaxSP3, data = dat, ordered = c("SP2", "SP3", "SP4", "SP5", "SP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 9 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesSP3, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 36 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 13.051 34.498
## Degrees of freedom 4 4
## P-value (Chi-square) 0.011 0.000
## Scaling correction factor 0.380
## Shift parameter 0.111
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 4246.983 2730.416
## Degrees of freedom 10 10
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.998 0.989
## Tucker-Lewis Index (TLI) 0.995 0.972
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.057 0.104
## 90 Percent Confidence Interval 0.024 0.092 0.074 0.137
## P-value RMSEA <= 0.05 0.322 0.002
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.026 0.026
##
## Weighted Root Mean Square Residual:
##
## WRMR 0.660 0.660
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP =~
## SP2 0.952 0.064 14.876 0.000 0.952 0.689
## SP3 0.850 0.059 14.286 0.000 0.850 0.648
## SP4 0.906 0.061 14.883 0.000 0.906 0.671
## SP5 1.708 0.128 13.333 0.000 1.708 0.863
## SP6 1.091 0.068 16.123 0.000 1.091 0.737
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .SP2 ~~
## .SP3 0.242 0.038 6.457 0.000 0.242 0.242
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 0.000 0.000 0.000
## .SP2 0.000 0.000 0.000
## .SP3 0.000 0.000 0.000
## .SP4 0.000 0.000 0.000
## .SP5 0.000 0.000 0.000
## .SP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP2|t1 -3.297 0.208 -15.889 0.000 -3.297 -2.388
## SP2|t2 -2.224 0.111 -20.008 0.000 -2.224 -1.611
## SP2|t3 -1.360 0.083 -16.444 0.000 -1.360 -0.985
## SP2|t4 0.450 0.065 6.942 0.000 0.450 0.326
## SP3|t1 -2.993 0.174 -17.209 0.000 -2.993 -2.281
## SP3|t2 -2.049 0.102 -20.035 0.000 -2.049 -1.561
## SP3|t3 -1.007 0.072 -14.071 0.000 -1.007 -0.767
## SP3|t4 0.858 0.067 12.788 0.000 0.858 0.654
## SP4|t1 -2.863 0.153 -18.724 0.000 -2.863 -2.122
## SP4|t2 -1.655 0.087 -19.085 0.000 -1.655 -1.226
## SP4|t3 -0.609 0.068 -8.947 0.000 -0.609 -0.452
## SP4|t4 1.175 0.076 15.564 0.000 1.175 0.871
## SP5|t1 -4.613 0.322 -14.328 0.000 -4.613 -2.331
## SP5|t2 -3.188 0.195 -16.344 0.000 -3.188 -1.611
## SP5|t3 -1.390 0.124 -11.187 0.000 -1.390 -0.702
## SP5|t4 1.372 0.114 12.080 0.000 1.372 0.693
## SP6|t1 -2.891 0.151 -19.103 0.000 -2.891 -1.953
## SP6|t2 -1.630 0.090 -18.018 0.000 -1.630 -1.101
## SP6|t3 -0.566 0.073 -7.788 0.000 -0.566 -0.382
## SP6|t4 1.080 0.077 14.032 0.000 1.080 0.730
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 1.000 1.000 1.000
## .SP2 1.000 1.000 0.525
## .SP3 1.000 1.000 0.581
## .SP4 1.000 1.000 0.549
## .SP5 1.000 1.000 0.255
## .SP6 1.000 1.000 0.457
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP2 0.724 0.724 1.000
## SP3 0.762 0.762 1.000
## SP4 0.741 0.741 1.000
## SP5 0.505 0.505 1.000
## SP6 0.676 0.676 1.000
##
## R-Square:
## Estimate
## SP2 0.475
## SP3 0.419
## SP4 0.451
## SP5 0.745
## SP6 0.543
fitmeasures(grm2PestimatesSP3)
## npar fmin
## 26.000 0.009
## chisq df
## 13.051 4.000
## pvalue chisq.scaled
## 0.011 34.498
## df.scaled pvalue.scaled
## 4.000 0.000
## chisq.scaling.factor baseline.chisq
## 0.380 4246.983
## baseline.df baseline.pvalue
## 10.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 2730.416 10.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 1.557
## cfi tli
## 0.998 0.995
## nnfi rfi
## 0.995 0.992
## nfi pnfi
## 0.997 0.399
## ifi rni
## 0.998 0.998
## cfi.scaled tli.scaled
## 0.989 0.972
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.972 NA
## rfi.scaled nfi.scaled
## 0.968 0.987
## ifi.scaled rni.scaled
## 0.987 0.993
## rni.robust rmsea
## NA 0.057
## rmsea.ci.lower rmsea.ci.upper
## 0.024 0.092
## rmsea.pvalue rmsea.scaled
## 0.322 0.104
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.074 0.137
## rmsea.pvalue.scaled rmsea.robust
## 0.002 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.023
## rmr_nomean srmr
## 0.026 0.026
## srmr_bentler srmr_bentler_nomean
## 0.023 0.026
## srmr_bollen srmr_bollen_nomean
## 0.023 0.026
## srmr_mplus srmr_mplus_nomean
## 0.023 0.026
## cn_05 cn_01
## 515.701 721.249
## gfi agfi
## 0.999 0.990
## pgfi mfi
## 0.133 0.994
modificationindices(grm2PestimatesSP3, sort. = TRUE)
## lhs op rhs mi mi.scaled epc sepc.lv sepc.all sepc.nox
## 51 SP4 ~~ SP6 9.957 26.235 -0.249 -0.249 -0.125 -0.125
## 50 SP4 ~~ SP5 5.564 14.661 0.266 0.266 0.100 0.100
## 49 SP3 ~~ SP6 4.707 12.402 0.164 0.164 0.084 0.084
## 45 SP2 ~~ SP5 2.701 7.116 -0.204 -0.204 -0.075 -0.075
## 48 SP3 ~~ SP5 2.027 5.341 -0.164 -0.164 -0.063 -0.063
## 44 SP2 ~~ SP4 1.813 4.776 0.099 0.099 0.053 0.053
## 47 SP3 ~~ SP4 0.607 1.600 -0.054 -0.054 -0.030 -0.030
## 52 SP5 ~~ SP6 0.280 0.739 0.073 0.073 0.025 0.025
## 46 SP2 ~~ SP6 0.201 0.528 0.037 0.037 0.018 0.018
The author conducted two models for evaluating Social Presense Scale to confirm the hypotheses. The previous model fit indices were as follows: (CFI = 0.989, TLI = 0.972, RMSEA = 0.104, SRMR = 0.026, RMR =0.023). All of the fit indices are eigher excellent or good except for, again, RMEAS (0.104). Therefore, I ran modificatinon indices function and found that SP4 and SP6 residuals should be correlated. When looking at the items themselves, we can see that both of these items as about communicaiotn, trust, and group cohesion which are all correlated constructs, which make sense to correlate their residuals. SP4:I felt comfortable disagreeing with other course participants while still maintaining a sense of trust.; SP6: Getting to know other course participants gave me a sense of belonging in the course,
Therefore, SP4 and SP6 residuals were correlated and the mdoel was run again.
grm2PsyntaxSP4 = "
SP =~ SP2 + SP3 + SP4 + SP5 + SP6
SP ~~ 1*SP
SP ~ 0
SP2 ~~ SP3
SP4 ~~ SP6"
grm2PestimatesSP4 = cfa(model = grm2PsyntaxSP4, data = dat, ordered = c("SP2", "SP3", "SP4", "SP5", "SP6"), std.lv = TRUE, parameterization="theta")
## Warning in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, : lavaan WARNING: 9 bivariate tables have empty cells; to see them, use:
## lavInspect(fit, "zero.cell.tables")
summary(grm2PestimatesSP4, fit.measures = TRUE, rsquare = TRUE, standardized = TRUE)
## lavaan (0.5-23.1097) converged normally after 42 iterations
##
## Number of observations 709
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 3.082 8.186
## Degrees of freedom 3 3
## P-value (Chi-square) 0.379 0.042
## Scaling correction factor 0.381
## Shift parameter 0.107
## for simple second-order correction (Mplus variant)
##
## Model test baseline model:
##
## Minimum Function Test Statistic 4246.983 2730.416
## Degrees of freedom 10 10
## P-value 0.000 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000 0.998
## Tucker-Lewis Index (TLI) 1.000 0.994
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.006 0.049
## 90 Percent Confidence Interval 0.000 0.064 0.008 0.091
## P-value RMSEA <= 0.05 0.857 0.437
##
## Robust RMSEA NA
## 90 Percent Confidence Interval NA NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.013 0.013
##
## Weighted Root Mean Square Residual:
##
## WRMR 0.321 0.321
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP =~
## SP2 0.924 0.061 15.137 0.000 0.924 0.679
## SP3 0.824 0.057 14.522 0.000 0.824 0.636
## SP4 1.016 0.074 13.788 0.000 1.016 0.713
## SP5 1.558 0.108 14.372 0.000 1.558 0.842
## SP6 1.221 0.086 14.165 0.000 1.221 0.774
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .SP2 ~~
## .SP3 0.262 0.036 7.269 0.000 0.262 0.262
## .SP4 ~~
## .SP6 -0.288 0.065 -4.417 0.000 -0.288 -0.288
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 0.000 0.000 0.000
## .SP2 0.000 0.000 0.000
## .SP3 0.000 0.000 0.000
## .SP4 0.000 0.000 0.000
## .SP5 0.000 0.000 0.000
## .SP6 0.000 0.000 0.000
##
## Thresholds:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP2|t1 -3.251 0.203 -16.003 0.000 -3.251 -2.388
## SP2|t2 -2.193 0.108 -20.268 0.000 -2.193 -1.611
## SP2|t3 -1.342 0.080 -16.674 0.000 -1.342 -0.985
## SP2|t4 0.443 0.064 6.937 0.000 0.443 0.326
## SP3|t1 -2.956 0.171 -17.332 0.000 -2.956 -2.281
## SP3|t2 -2.023 0.100 -20.261 0.000 -2.023 -1.561
## SP3|t3 -0.995 0.070 -14.166 0.000 -0.995 -0.767
## SP3|t4 0.847 0.066 12.821 0.000 0.847 0.654
## SP4|t1 -3.024 0.168 -18.032 0.000 -3.024 -2.122
## SP4|t2 -1.748 0.097 -17.972 0.000 -1.748 -1.226
## SP4|t3 -0.644 0.073 -8.785 0.000 -0.644 -0.452
## SP4|t4 1.242 0.083 14.893 0.000 1.242 0.871
## SP5|t1 -4.316 0.283 -15.273 0.000 -4.316 -2.331
## SP5|t2 -2.983 0.167 -17.885 0.000 -2.983 -1.611
## SP5|t3 -1.301 0.111 -11.767 0.000 -1.301 -0.702
## SP5|t4 1.284 0.101 12.661 0.000 1.284 0.693
## SP6|t1 -3.084 0.176 -17.519 0.000 -3.084 -1.953
## SP6|t2 -1.738 0.104 -16.746 0.000 -1.738 -1.101
## SP6|t3 -0.603 0.078 -7.719 0.000 -0.603 -0.382
## SP6|t4 1.152 0.087 13.304 0.000 1.152 0.730
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP 1.000 1.000 1.000
## .SP2 1.000 1.000 0.540
## .SP3 1.000 1.000 0.595
## .SP4 1.000 1.000 0.492
## .SP5 1.000 1.000 0.292
## .SP6 1.000 1.000 0.401
##
## Scales y*:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SP2 0.735 0.735 1.000
## SP3 0.772 0.772 1.000
## SP4 0.702 0.702 1.000
## SP5 0.540 0.540 1.000
## SP6 0.633 0.633 1.000
##
## R-Square:
## Estimate
## SP2 0.460
## SP3 0.405
## SP4 0.508
## SP5 0.708
## SP6 0.599
fitmeasures(grm2PestimatesSP4)
## npar fmin
## 27.000 0.002
## chisq df
## 3.082 3.000
## pvalue chisq.scaled
## 0.379 8.186
## df.scaled pvalue.scaled
## 3.000 0.042
## chisq.scaling.factor baseline.chisq
## 0.381 4246.983
## baseline.df baseline.pvalue
## 10.000 0.000
## baseline.chisq.scaled baseline.df.scaled
## 2730.416 10.000
## baseline.pvalue.scaled baseline.chisq.scaling.factor
## 0.000 1.557
## cfi tli
## 1.000 1.000
## nnfi rfi
## 1.000 0.998
## nfi pnfi
## 0.999 0.300
## ifi rni
## 1.000 1.000
## cfi.scaled tli.scaled
## 0.998 0.994
## cfi.robust tli.robust
## NA NA
## nnfi.scaled nnfi.robust
## 0.994 NA
## rfi.scaled nfi.scaled
## 0.990 0.997
## ifi.scaled rni.scaled
## 0.997 0.999
## rni.robust rmsea
## NA 0.006
## rmsea.ci.lower rmsea.ci.upper
## 0.000 0.064
## rmsea.pvalue rmsea.scaled
## 0.857 0.049
## rmsea.ci.lower.scaled rmsea.ci.upper.scaled
## 0.008 0.091
## rmsea.pvalue.scaled rmsea.robust
## 0.437 NA
## rmsea.ci.lower.robust rmsea.ci.upper.robust
## NA NA
## rmsea.pvalue.robust rmr
## NA 0.011
## rmr_nomean srmr
## 0.013 0.013
## srmr_bentler srmr_bentler_nomean
## 0.011 0.013
## srmr_bollen srmr_bollen_nomean
## 0.011 0.013
## srmr_mplus srmr_mplus_nomean
## 0.011 0.013
## cn_05 cn_01
## 1796.197 2607.140
## gfi agfi
## 1.000 0.997
## pgfi mfi
## 0.100 1.000
Finally, the author conducted two models for evaluating Social Presense Scale to confirm the hypotheses. The previous model fit indices were as follows: (CFI = 0.998, TLI = 0.994, RMSEA = 0.049, SRMR = 0.013, RMR =0.011). All of the fit indices are excellent, I conclude that this is the final model for the social presence scale.
Correlation matrix for Social Presence Items:
SP_cor_table <- residuals(grm2PestimatesSP4, type = "cor")$cor
SP_cor_table[upper.tri(SP_cor_table)] <- NA
diag(SP_cor_table) <- NA
kable(SP_cor_table, digits=2)
SP2 | SP3 | SP4 | SP5 | SP6 | |
---|---|---|---|---|---|
SP2 | NA | NA | NA | NA | NA |
SP3 | 0.00 | NA | NA | NA | NA |
SP4 | 0.01 | -0.04 | NA | NA | NA |
SP5 | 0.00 | 0.00 | 0.01 | NA | NA |
SP6 | -0.01 | 0.03 | 0.00 | -0.01 | NA |
library (knitr)
library(dplyr)
library(tidyr)
parameterEstimates(grm2PestimatesSP4, standardized=TRUE) %>%
filter(op == "=~") %>%
select('Latent Factor'=lhs, Indicator=rhs, B=est, SE=se, Z=z, 'p-value'=pvalue, Beta=std.all) %>%
kable(digits = 3, format="pandoc", caption="Factor Loadings")
Latent Factor | Indicator | B | SE | Z | p-value | Beta |
---|---|---|---|---|---|---|
SP | SP2 | 0.924 | 0.061 | 15.137 | 0 | 0.679 |
SP | SP3 | 0.824 | 0.057 | 14.522 | 0 | 0.636 |
SP | SP4 | 1.016 | 0.074 | 13.788 | 0 | 0.713 |
SP | SP5 | 1.558 | 0.108 | 14.372 | 0 | 0.842 |
SP | SP6 | 1.221 | 0.086 | 14.165 | 0 | 0.774 |
{r} anova(grm2PestimatesSP1, grm2PestimatesSP4) #
Plotting Social Presence Scale items
lavaanCatItemPlot = function(lavObject, varname, sds = 3){
output = inspect(object = lavObject, what = "est")
if (!varname %in% rownames(output$lambda)) stop(paste(varname, "not found in lavaan object"))
if (dim(output$lambda)[2]>1) stop("plots only given for one factor models")
itemloading = output$lambda[which(rownames(output$lambda) == varname),1]
itemthresholds = output$tau[grep(pattern = varname, x = rownames(output$tau))]
factorname = colnames(output$lambda)
factormean = output$alpha[which(rownames(output$alpha) == factorname)]
factorvar = output$psi[which(rownames(output$psi) == factorname)]
factormin = factormean - 3*sqrt(factorvar)
factormax = factormean + 3*sqrt(factorvar)
factorX = seq(factormin, factormax, .01)
itemloc = which(lavObject@Data@ov$name == varname)
itemlevels = unlist(strsplit(x = lavObject@Data@ov$lnam[itemloc], split = "\\|"))
if (length(itemthresholds)>1){
plotdata = NULL
plotdata2 = NULL
itemY = NULL
itemY2 = NULL
itemX = NULL
itemText = NULL
for (level in 1:length(itemthresholds)){
itemY = pnorm(q = -1*itemthresholds[level] + itemloading*factorX)
itemY2 = cbind(itemY2, pnorm(q = -1*itemthresholds[level] + itemloading*factorX))
itemText = paste0("P(", varname, " > ", itemlevels[level], ")")
itemText2 = paste0("P(", varname, " = ", itemlevels[level], ")")
plotdata = rbind(plotdata, data.frame(factor = factorX, prob = itemY, plot = itemText))
if (level == 1){
plotdata2 = data.frame(factor = factorX, plot = itemText2, prob = matrix(1, nrow = dim(itemY2)[1], ncol=1) - itemY2[,level])
} else if (level == length(itemthresholds)){
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level]))
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = paste0("P(", varname, " = ", itemlevels[level+1], ")"), prob = itemY2[,level]))
} else {
plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level]))
}
}
names(plotdata) = c(factorname , "Probability", "Cumulative")
ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Cumulative")) + geom_line(size = 2)
names(plotdata2) = c(factorname, "Response", "Probability")
ggplot(data = plotdata2, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2)
} else {
itemY = pnorm(q = -1*itemthresholds[1] + itemloading*factorX)
itemText2 = paste0("P(", varname, " = ", itemlevels[1], ")")
plotdata = data.frame(factor = factorX, prob = itemY, plot = itemText2)
names(plotdata) = c(factorname , "Probability", "Response")
ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2)
}
}
lavaanCatItemPlot(lavObject = grm2PestimatesSP4, varname = "SP2", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesSP4, varname = "SP3", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesSP4, varname = "SP4", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesSP4, varname = "SP5", sds = 3)
lavaanCatItemPlot(lavObject = grm2PestimatesSP4, varname = "SP6", sds = 3)
Social Presence Factor Score:
factor_scoresSP <- predict(grm2PestimatesSP4)
SP<- factor_scoresSP[,]
ggplot() +
geom_density(aes(x = SP), color = "red", alpha = 0.45, fill ="gold") +
xlim(-3,3) +
ggtitle("Social Presence Factor Distribution")+
theme(panel.background = element_blank()) +
ylab("Probability")+
xlab("theta")