Data Import and data cleaning

library(rio)
library(stats)
library(psych)
library(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
library(CTT)
## 
## Attaching package: 'CTT'
## The following object is masked from 'package:psych':
## 
##     polyserial
VL <-read.csv("/Users/Lorraine/Desktop/Virtual Learning1.csv")
data <- VL[,31:61]
#changing the first row as column name (It will work if the columns are factors or characters)
names(data) <- lapply(data[1, ], as.character)
data <- data[-1,]
#changing all scale reponses to numaric values
datatran <- ifelse(
 data == "1 - disagree", 1, ifelse(
    data == "2 - somewhat disagree", 2, ifelse(
      data == "3 - somewhat agree", 3, ifelse(
        data == "4 - agree", 4, NA)
      )
    )
  )
datatran <- as.data.frame(datatran)
summary(datatran)
##  I am easily distracted by other things at home (people, pets, food, electronics, etc.) during virtual classes.
##  Min.   :1.000                                                                                                 
##  1st Qu.:3.000                                                                                                 
##  Median :3.000                                                                                                 
##  Mean   :3.234                                                                                                 
##  3rd Qu.:4.000                                                                                                 
##  Max.   :4.000                                                                                                 
##  NA's   :23                                                                                                    
##  There are more distractions during in-person classes than in virtual classes.
##  Min.   :1.000                                                                
##  1st Qu.:1.000                                                                
##  Median :2.000                                                                
##  Mean   :1.896                                                                
##  3rd Qu.:2.000                                                                
##  Max.   :4.000                                                                
##  NA's   :23                                                                   
##  Virtual learning can accomplish the same objectives as in-person learning.
##  Min.   :1.000                                                             
##  1st Qu.:2.000                                                             
##  Median :3.000                                                             
##  Mean   :2.636                                                             
##  3rd Qu.:3.000                                                             
##  Max.   :4.000                                                             
##  NA's   :23                                                                
##  It is easier for me to learn new material when I am physically present in a classroom.
##  Min.   :1.000                                                                         
##  1st Qu.:3.000                                                                         
##  Median :3.000                                                                         
##  Mean   :3.221                                                                         
##  3rd Qu.:4.000                                                                         
##  Max.   :4.000                                                                         
##  NA's   :23                                                                            
##  I learn more effectively from virtual classes than in-person classes.
##  Min.   :1.000                                                        
##  1st Qu.:1.000                                                        
##  Median :2.000                                                        
##  Mean   :1.948                                                        
##  3rd Qu.:3.000                                                        
##  Max.   :4.000                                                        
##  NA's   :23                                                           
##  I am more focused during in-person classes than in virtual classes.
##  Min.   :1.000                                                      
##  1st Qu.:3.000                                                      
##  Median :3.000                                                      
##  Mean   :3.208                                                      
##  3rd Qu.:4.000                                                      
##  Max.   :4.000                                                      
##  NA's   :23                                                         
##  I better retain information during in-person classes than in virtual classes.
##  Min.   :1.000                                                                
##  1st Qu.:3.000                                                                
##  Median :3.000                                                                
##  Mean   :3.195                                                                
##  3rd Qu.:4.000                                                                
##  Max.   :4.000                                                                
##  NA's   :23                                                                   
##  I take better notes for in-person classes than I do in virtual classes.
##  Min.   :1.000                                                          
##  1st Qu.:2.000                                                          
##  Median :3.000                                                          
##  Mean   :2.844                                                          
##  3rd Qu.:4.000                                                          
##  Max.   :4.000                                                          
##  NA's   :23                                                             
##  My work on assignments is of a higher quality when I attend in-person classes.
##  Min.   :1.000                                                                 
##  1st Qu.:2.000                                                                 
##  Median :3.000                                                                 
##  Mean   :2.779                                                                 
##  3rd Qu.:3.000                                                                 
##  Max.   :4.000                                                                 
##  NA's   :23                                                                    
##  In-person classes are more appropriate for my learning style than virtual classes.
##  Min.   :1.000                                                                     
##  1st Qu.:3.000                                                                     
##  Median :3.000                                                                     
##  Mean   :3.156                                                                     
##  3rd Qu.:4.000                                                                     
##  Max.   :4.000                                                                     
##  NA's   :23                                                                        
##  I ask fewer questions during virtual classes than I would ask if the class was in-person.
##  Min.   :1.000                                                                            
##  1st Qu.:2.000                                                                            
##  Median :3.000                                                                            
##  Mean   :2.597                                                                            
##  3rd Qu.:3.000                                                                            
##  Max.   :4.000                                                                            
##  NA's   :23                                                                               
##  I spend the same amount of time studying on my own, whether classes are in-person or virtual.
##  Min.   :1.00                                                                                 
##  1st Qu.:2.00                                                                                 
##  Median :3.00                                                                                 
##  Mean   :2.74                                                                                 
##  3rd Qu.:4.00                                                                                 
##  Max.   :4.00                                                                                 
##  NA's   :23                                                                                   
##  It requires more effort to understand class material presented virtually than in-person.
##  Min.   :1.000                                                                           
##  1st Qu.:2.000                                                                           
##  Median :3.000                                                                           
##  Mean   :2.857                                                                           
##  3rd Qu.:4.000                                                                           
##  Max.   :4.000                                                                           
##  NA's   :23                                                                              
##  Virtual classes require better time management than in-person classes.
##  Min.   :1.000                                                         
##  1st Qu.:2.000                                                         
##  Median :3.000                                                         
##  Mean   :2.974                                                         
##  3rd Qu.:4.000                                                         
##  Max.   :4.000                                                         
##  NA's   :23                                                            
##  It is easier to manage my time for virtual classes than in-person classes.
##  Min.   :1.000                                                             
##  1st Qu.:2.000                                                             
##  Median :2.000                                                             
##  Mean   :2.545                                                             
##  3rd Qu.:4.000                                                             
##  Max.   :4.000                                                             
##  NA's   :23                                                                
##  When there are distractions around, I focus better during in-person classes than in virtual classes.
##  Min.   :1.000                                                                                       
##  1st Qu.:3.000                                                                                       
##  Median :4.000                                                                                       
##  Mean   :3.338                                                                                       
##  3rd Qu.:4.000                                                                                       
##  Max.   :4.000                                                                                       
##  NA's   :23                                                                                          
##  It is easier to ask questions during virtual classes than during in-person classes.
##  Min.   :1.000                                                                      
##  1st Qu.:2.000                                                                      
##  Median :2.000                                                                      
##  Mean   :2.338                                                                      
##  3rd Qu.:3.000                                                                      
##  Max.   :4.000                                                                      
##  NA's   :23                                                                         
##  It is easier to discuss material with others during virtual classes than during in-person classes.
##  Min.   :1.000                                                                                     
##  1st Qu.:1.000                                                                                     
##  Median :2.000                                                                                     
##  Mean   :1.883                                                                                     
##  3rd Qu.:2.000                                                                                     
##  Max.   :4.000                                                                                     
##  NA's   :23                                                                                        
##  Team projects are easier to accomplish for in-person classes than for virtual classes.
##  Min.   :1.000                                                                         
##  1st Qu.:2.000                                                                         
##  Median :3.000                                                                         
##  Mean   :3.143                                                                         
##  3rd Qu.:4.000                                                                         
##  Max.   :4.000                                                                         
##  NA's   :23                                                                            
##  I need additional support for virtual learning compared to in-person classes.
##  Min.   :1.000                                                                
##  1st Qu.:2.000                                                                
##  Median :3.000                                                                
##  Mean   :2.662                                                                
##  3rd Qu.:3.000                                                                
##  Max.   :4.000                                                                
##  NA's   :23                                                                   
##  The quality of my social interactions is better with virtual classes than with in-person classes.
##  Min.   :1.000                                                                                    
##  1st Qu.:1.000                                                                                    
##  Median :1.000                                                                                    
##  Mean   :1.649                                                                                    
##  3rd Qu.:2.000                                                                                    
##  Max.   :4.000                                                                                    
##  NA's   :23                                                                                       
##  Collaboration with classmates is more conducive to learning during in-person classes than virtual classes.
##  Min.   :1.00                                                                                              
##  1st Qu.:3.00                                                                                              
##  Median :3.00                                                                                              
##  Mean   :3.26                                                                                              
##  3rd Qu.:4.00                                                                                              
##  Max.   :4.00                                                                                              
##  NA's   :23                                                                                                
##  Instructors provide more individual attention for in-person classes than for virtual classes.
##  Min.   :1.000                                                                                
##  1st Qu.:2.000                                                                                
##  Median :3.000                                                                                
##  Mean   :2.883                                                                                
##  3rd Qu.:4.000                                                                                
##  Max.   :4.000                                                                                
##  NA's   :23                                                                                   
##  Instructors can respond to questions more promptly during virtual classes than in-person classes.
##  Min.   :1.000                                                                                    
##  1st Qu.:2.000                                                                                    
##  Median :2.000                                                                                    
##  Mean   :2.273                                                                                    
##  3rd Qu.:3.000                                                                                    
##  Max.   :4.000                                                                                    
##  NA's   :23                                                                                       
##  Instructors are easier to contact for in-person classes than for virtual classes.
##  Min.   :1.00                                                                     
##  1st Qu.:2.00                                                                     
##  Median :3.00                                                                     
##  Mean   :2.61                                                                     
##  3rd Qu.:3.00                                                                     
##  Max.   :4.00                                                                     
##  NA's   :23                                                                       
##  Learning resources are more accessible for virtual classes than for in-person classes.
##  Min.   :1.000                                                                         
##  1st Qu.:2.000                                                                         
##  Median :2.000                                                                         
##  Mean   :2.481                                                                         
##  3rd Qu.:3.000                                                                         
##  Max.   :4.000                                                                         
##  NA's   :23                                                                            
##  The instructor better communicates the information when they teach virtual classes.
##  Min.   :1.000                                                                      
##  1st Qu.:2.000                                                                      
##  Median :2.000                                                                      
##  Mean   :2.117                                                                      
##  3rd Qu.:3.000                                                                      
##  Max.   :4.000                                                                      
##  NA's   :23                                                                         
##  Instructors can be as effective in teaching virtually as they would in-person.
##  Min.   :1.000                                                                 
##  1st Qu.:2.000                                                                 
##  Median :3.000                                                                 
##  Mean   :2.636                                                                 
##  3rd Qu.:3.000                                                                 
##  Max.   :4.000                                                                 
##  NA's   :23                                                                    
##  There are more technical problems during in-person classes than during virtual classes.
##  Min.   :1.000                                                                          
##  1st Qu.:1.000                                                                          
##  Median :2.000                                                                          
##  Mean   :1.766                                                                          
##  3rd Qu.:2.000                                                                          
##  Max.   :4.000                                                                          
##  NA's   :23                                                                             
##  Online resources the school provides are just as useful as the on-campus resources.
##  Min.   :1.000                                                                      
##  1st Qu.:2.000                                                                      
##  Median :2.000                                                                      
##  Mean   :2.338                                                                      
##  3rd Qu.:3.000                                                                      
##  Max.   :4.000                                                                      
##  NA's   :23                                                                         
##  Team projects are easier to accomplish for virtual classes than for in-person classes.
##  Min.   :1.000                                                                         
##  1st Qu.:1.000                                                                         
##  Median :2.000                                                                         
##  Mean   :1.974                                                                         
##  3rd Qu.:3.000                                                                         
##  Max.   :4.000                                                                         
##  NA's   :23
final <- na.omit(datatran)

##Reverse code some items

final[,c(1,4,6,7,8,9,10,11,13,14,16,19,20,22,23,25)] <- 5-final[,c(1,4,6,7,8,9,10,11,13,14,16,19,20,22,23,25)]

Item Analysis

itemanalysis <- itemAnalysis(final)
itemanalysis$itemReport
##                                                                                                          itemName
## 1  I am easily distracted by other things at home (people, pets, food, electronics, etc.) during virtual classes.
## 2                                   There are more distractions during in-person classes than in virtual classes.
## 3                                      Virtual learning can accomplish the same objectives as in-person learning.
## 4                          It is easier for me to learn new material when I am physically present in a classroom.
## 5                                           I learn more effectively from virtual classes than in-person classes.
## 6                                             I am more focused during in-person classes than in virtual classes.
## 7                                   I better retain information during in-person classes than in virtual classes.
## 8                                         I take better notes for in-person classes than I do in virtual classes.
## 9                                  My work on assignments is of a higher quality when I attend in-person classes.
## 10                             In-person classes are more appropriate for my learning style than virtual classes.
## 11                      I ask fewer questions during virtual classes than I would ask if the class was in-person.
## 12                  I spend the same amount of time studying on my own, whether classes are in-person or virtual.
## 13                       It requires more effort to understand class material presented virtually than in-person.
## 14                                         Virtual classes require better time management than in-person classes.
## 15                                     It is easier to manage my time for virtual classes than in-person classes.
## 16           When there are distractions around, I focus better during in-person classes than in virtual classes.
## 17                            It is easier to ask questions during virtual classes than during in-person classes.
## 18             It is easier to discuss material with others during virtual classes than during in-person classes.
## 19                         Team projects are easier to accomplish for in-person classes than for virtual classes.
## 20                                  I need additional support for virtual learning compared to in-person classes.
## 21              The quality of my social interactions is better with virtual classes than with in-person classes.
## 22     Collaboration with classmates is more conducive to learning during in-person classes than virtual classes.
## 23                  Instructors provide more individual attention for in-person classes than for virtual classes.
## 24              Instructors can respond to questions more promptly during virtual classes than in-person classes.
## 25                              Instructors are easier to contact for in-person classes than for virtual classes.
## 26                         Learning resources are more accessible for virtual classes than for in-person classes.
## 27                            The instructor better communicates the information when they teach virtual classes.
## 28                                 Instructors can be as effective in teaching virtually as they would in-person.
## 29                        There are more technical problems during in-person classes than during virtual classes.
## 30                            Online resources the school provides are just as useful as the on-campus resources.
## 31                         Team projects are easier to accomplish for virtual classes than for in-person classes.
##    itemMean      pBis       bis alphaIfDeleted
## 1  1.766234 0.4740298 0.5353088      0.9083742
## 2  1.896104 0.3853470 0.4259674      0.9097621
## 3  2.636364 0.5574134 0.5995997      0.9071348
## 4  1.779221 0.7374357 0.8298587      0.9043536
## 5  1.948052 0.6833907 0.7473165      0.9054323
## 6  1.792208 0.6533313 0.7337908      0.9056155
## 7  1.805195 0.7406975 0.8291435      0.9042723
## 8  2.155844 0.5529365 0.5996994      0.9070404
## 9  2.220779 0.4828177 0.5174659      0.9082325
## 10 1.844156 0.5520796 0.6105313      0.9073007
## 11 2.402597 0.4196468 0.4504798      0.9094650
## 12 2.740260 0.2733637 0.2937089      0.9117991
## 13 2.142857 0.5602940 0.6035915      0.9070010
## 14 2.025974 0.1871437 0.2040451      0.9129824
## 15 2.545455 0.4947161 0.5330181      0.9081394
## 16 1.662338 0.4696559 0.5451406      0.9084523
## 17 2.337662 0.4319659 0.4629120      0.9090599
## 18 1.883117 0.5144283 0.5671469      0.9078627
## 19 1.857143 0.5836851 0.6506986      0.9066269
## 20 2.337662 0.3429384 0.3660726      0.9104563
## 21 1.649351 0.3918002 0.4489738      0.9095410
## 22 1.740260 0.4735872 0.5320679      0.9084367
## 23 2.116883 0.5050525 0.5461850      0.9078716
## 24 2.272727 0.4142062 0.4449395      0.9092485
## 25 2.389610 0.4953866 0.5299918      0.9080418
## 26 2.480519 0.2341823 0.2497966      0.9119856
## 27 2.116883 0.4895603 0.5343205      0.9082805
## 28 2.636364 0.5603820 0.5993029      0.9069368
## 29 1.766234 0.3143333 0.3551489      0.9107635
## 30 2.337662 0.4723798 0.5052873      0.9084002
## 31 1.974026 0.4188737 0.4580460      0.9092440
itemanalysis$alpha
## [1] 0.9110495

##EFA

fa.parallel(final, fm = "pa", fa = "fa", n.iter = 500)

## Parallel analysis suggests that the number of factors =  4  and the number of components =  NA
## 4 factor, changing column names cuz it's messy on the output
colnames(final) <- final[1,"q1:q30"]
loadingz4 <- fa(final, rotate = "promax", fm = "pa", nfactors = 4)
## Loading required namespace: GPArotation
print.psych(loadingz4, cut = .3, sort = TRUE)
## Factor Analysis using method =  pa
## Call: fa(r = final, nfactors = 4, rotate = "promax", fm = "pa")
## Standardized loadings (pattern matrix) based upon correlation matrix
##    item   PA1   PA3   PA2   PA4   h2   u2 com
## 7     7  0.85                   0.77 0.23 1.0
## 4     4  0.82                   0.77 0.23 1.1
## 6     6  0.80                   0.66 0.34 1.2
## 10   10  0.62                   0.45 0.55 1.3
## 8     8  0.60  0.36             0.53 0.47 1.9
## 12   12  0.60                   0.35 0.65 1.7
## 9     9  0.57                   0.34 0.66 1.1
## 13   13  0.54                   0.42 0.58 1.3
## 20   20  0.50                   0.23 0.77 1.3
## 1     1  0.43                   0.29 0.71 1.6
## 5     5  0.42              0.42 0.61 0.39 2.8
## 29   29  0.39                   0.19 0.81 1.8
## 2     2  0.38                   0.22 0.78 1.5
## 27   27  0.32                   0.32 0.68 2.8
## 15   15  0.32                   0.28 0.72 2.5
## 24   24        0.89 -0.33       0.71 0.29 1.4
## 17   17        0.80             0.62 0.38 1.3
## 23   23        0.58             0.48 0.52 1.4
## 11   11        0.51  0.35       0.47 0.53 2.0
## 25   25        0.42             0.34 0.66 1.7
## 3     3                         0.36 0.64 3.2
## 31   31              0.71       0.53 0.47 1.4
## 22   22              0.66       0.49 0.51 1.0
## 21   21              0.55  0.36 0.43 0.57 2.1
## 18   18              0.54  0.44 0.55 0.45 2.2
## 19   19        0.36  0.48       0.57 0.43 2.1
## 16   16  0.30        0.46       0.37 0.63 1.9
## 14   14              0.43       0.16 0.84 1.4
## 28   28                    0.57 0.54 0.46 1.4
## 30   30                    0.52 0.43 0.57 1.5
## 26   26                    0.50 0.25 0.75 1.3
## 
##                        PA1  PA3  PA2  PA4
## SS loadings           5.54 3.05 2.96 2.19
## Proportion Var        0.18 0.10 0.10 0.07
## Cumulative Var        0.18 0.28 0.37 0.44
## Proportion Explained  0.40 0.22 0.22 0.16
## Cumulative Proportion 0.40 0.63 0.84 1.00
## 
##  With factor correlations of 
##      PA1  PA3  PA2  PA4
## PA1 1.00 0.41 0.40 0.35
## PA3 0.41 1.00 0.44 0.21
## PA2 0.40 0.44 1.00 0.18
## PA4 0.35 0.21 0.18 1.00
## 
## Mean item complexity =  1.7
## Test of the hypothesis that 4 factors are sufficient.
## 
## The degrees of freedom for the null model are  465  and the objective function was  19.11 with Chi Square of  1239.15
## The degrees of freedom for the model are 347  and the objective function was  7.03 
## 
## The root mean square of the residuals (RMSR) is  0.07 
## The df corrected root mean square of the residuals is  0.08 
## 
## The harmonic number of observations is  77 with the empirical chi square  315.53  with prob <  0.89 
## The total number of observations was  77  with Likelihood Chi Square =  437.21  with prob <  0.00071 
## 
## Tucker Lewis Index of factoring reliability =  0.833
## RMSEA index =  0.084  and the 90 % confidence intervals are  0.039 NA
## BIC =  -1070.09
## Fit based upon off diagonal values = 0.95
## Measures of factor score adequacy             
##                                                    PA1  PA3  PA2 PA4
## Correlation of (regression) scores with factors   0.97 0.94 0.92 0.9
## Multiple R square of scores with factors          0.94 0.88 0.85 0.8
## Minimum correlation of possible factor scores     0.88 0.76 0.70 0.6