AFC

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

### Librerías necesarias
library(GPArotation)
library(readxl)#Leer excel
library(psych) #Datos descriptivos y m?s

Adjuntando el paquete: 'psych'
The following objects are masked from 'package:GPArotation':

    equamax, varimin
library(dplyr) #Funci?n %>%

Adjuntando el paquete: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(lavaan)#AFC
This is lavaan 0.6-18
lavaan is FREE software! Please report any bugs.

Adjuntando el paquete: 'lavaan'
The following object is masked from 'package:psych':

    cor2cov
library(semTools)#Invarianza
 
###############################################################################
This is semTools 0.5-6
All users of R (or SEM) are invited to submit functions or ideas for functions.
###############################################################################

Adjuntando el paquete: 'semTools'
The following objects are masked from 'package:psych':

    reliability, skew
library(parameters)#n_factors

Adjuntando el paquete: 'parameters'
The following object is masked from 'package:semTools':

    kurtosis
library(semPlot)#graficos de aFC
library(EFAtools)#omega Y AFE

Adjuntando el paquete: 'EFAtools'
The following object is masked from 'package:psych':

    KMO
library(readxl)#leer
library(MBESS)#intervalos de confianza del omega

Adjuntando el paquete: 'MBESS'
The following object is masked from 'package:lavaan':

    cor2cov
The following object is masked from 'package:psych':

    cor2cov
library(openxlsx)#Guardar
library(MVN)#normalidad
library(PerformanceAnalytics)#Grafico de las correlaciones
Cargando paquete requerido: xts
Cargando paquete requerido: zoo

Adjuntando el paquete: 'zoo'
The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

######################### Warning from 'xts' package ##########################
#                                                                             #
# The dplyr lag() function breaks how base R's lag() function is supposed to  #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
# source() into this session won't work correctly.                            #
#                                                                             #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
# dplyr from breaking base R's lag() function.                                #
#                                                                             #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
#                                                                             #
###############################################################################

Adjuntando el paquete: 'xts'
The following objects are masked from 'package:dplyr':

    first, last

Adjuntando el paquete: 'PerformanceAnalytics'
The following objects are masked from 'package:parameters':

    kurtosis, skewness
The following object is masked from 'package:semTools':

    kurtosis
The following object is masked from 'package:graphics':

    legend
library(corrr)
library(foreign)
library(haven)
library(MVN)
library(lavaanPlot)
library(kableExtra)

Adjuntando el paquete: 'kableExtra'
The following object is masked from 'package:dplyr':

    group_rows
library(gptstudio)
library(shiny)
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.4.2
Warning: package 'lubridate' was built under R version 4.4.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ readr     2.1.5
✔ ggplot2   3.5.1     ✔ stringr   1.5.1
✔ lubridate 1.9.3     ✔ tibble    3.2.1
✔ purrr     1.0.2     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ ggplot2::%+%()           masks psych::%+%()
✖ ggplot2::alpha()         masks psych::alpha()
✖ readr::clipboard()       masks semTools::clipboard()
✖ dplyr::filter()          masks stats::filter()
✖ xts::first()             masks dplyr::first()
✖ kableExtra::group_rows() masks dplyr::group_rows()
✖ dplyr::lag()             masks stats::lag()
✖ xts::last()              masks dplyr::last()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Base de dato

da <- read_sav("D:/Bases de datos/ESCALA TMMS-24.sav")

Creando un subconjunto de índices de ajuste que examinaremos en todos los modelos

```{fit.subset<-c(“chisq.scaled”, “pvalue.scaled”, “df.scaled”,“cfi.scaled”, “tli.scaled”, “rmsea.scaled”, “rmsea.ci.lower.scaled”,“rmsea.ci.upper.scaled”, “srmr”,“wrmr”)}

##---------------------------------------------------------------------------------------------------------- #Análisis factorial confirmatorio \# Probaremos modelos #1) Modelo unidimensional congenerico
UNI.CFA.CONG<-'G=~E1+E2+E3+E4+E5+E6+E7+E8+E9+ E10+E11+E12+E13+E14+E15+E16+E17+E18+E19+E20 +E21+E22+E23+E24'

#Estimación

fit.UNI.CFA.CONG<-cfa(model = UNI.CFA.CONG, data =da,estimator="WLSMV", mimic="Mplus", ordered = T) #std.lv=TRUE Colocar si es necesario igualar a 1 la regresi?n}

Evaluación

fit.subset<-c("chisq.scaled", "pvalue.scaled",
              "df.scaled","cfi.scaled", 
              "tli.scaled", "rmsea.scaled",
              "rmsea.ci.lower.scaled","rmsea.ci.upper.scaled",
              "srmr","wrmr")
fitmeasures(fit.UNI.CFA.CONG, fit.subset)
         chisq.scaled         pvalue.scaled             df.scaled 
            10199.305                 0.000               252.000 
           cfi.scaled            tli.scaled          rmsea.scaled 
                0.791                 0.771                 0.138 
rmsea.ci.lower.scaled rmsea.ci.upper.scaled                  srmr 
                0.136                 0.141                 0.087 
                 wrmr 
                4.937 
#Path analisis
semPaths(fit.UNI.CFA.CONG, whatLabels="std",
         style = "lisrel", layout = "tree3", 
         intercepts = FALSE, residuals = FALSE, thresholds = FALSE,
         rotation = 1, sizeMan = 2,sizeLat = 8, shapeMan = "rectangle", shapeLat = "circle"          ,edge.color ="black", nDigits = 2, edge.label.cex = 0.6, label.prop=2)