## Example from Venables and Ripley (2002, p. 323)
## Previously from Bartholomew and Knott (1999, p. 68--72)
## Originally from Smith and Stanley (1983)
data(ability.cov)
print(ability.cov)
if(TRUE){ # NOTE: One would usually not bother with this block. It just makes the
# example go quickly and without user intervention on the pop-up menus.
starts1 <- c(0.4551693481819578,
0.5893203083906567,
0.2182044732474321,
0.7694294930481663,
0.0526383747875095,
0.3334323600411430)
starts1 <- matrix(starts1, nrow = 1)
example1 <- new("restrictions.factanal", factors = 2L, nvars = 6L,
Domains = cbind(sqrt(.Machine$double.eps), rep(1, 6)),
model = "EFA", method = "MLE", dof = 4L, fast = FALSE)
}
# 'restrictions' and 'starting.values' would typically be left unspecified!
efa <- Factanal(covmat = ability.cov, factors = 2, model = "EFA",
restrictions = example1, starting.values = starts1)
show(efa)
summary(efa)
# 'criteria' would typically be left unspecified!
efa.rotated <- Rotate(efa, criteria = list("phi"))
summary(efa.rotated)
if(TRUE){ # NOTE: One would usually not bother with this block. It just makes the
# example go quickly and without user intervention on the pop-up menus.
starts2 <- c(4.46294498156615e-01,
4.67036349420035e-01,
6.42220238211291e-01,
8.88564379236454e-01,
4.77779639176941e-01,
-7.13405536379741e-02,
-9.47782525342137e-08,
4.04993872375487e-01,
-1.04604290549591e-08,
-9.44950629176182e-03,
2.63078925240678e-04,
9.38038168787216e-01,
8.43618801925473e-01,
4.49024212016027e-01,
5.87550265675745e-01,
2.17850254355888e-01,
7.71724777627142e-01,
1.20084009542348e-01,
2.88308011310065e-01)
starts2 <- matrix(starts2, nrow = 1)
Domains <- cbind(-1, 1)
Domains <- rbind(Domains, cbind(-1.5, rep(1.5, 12)))
Domains <- rbind(Domains, cbind(0, rep(1, 6)))
fixed <- matrix(NA_real_, nrow = 6, ncol = 2)
fix_beta_args <- as.list(formals(FAiR:::FAiR_fix_coefficients))
fix_beta_args$zeros <- c(2,2)
beta_select <- c(FALSE, rep(TRUE, length(fixed)), rep(FALSE, nrow(fixed)))
beta_list <- list(beta = fixed, free = c(is.na(fixed)),
num_free = length(fixed), select = beta_select,
fix_beta_args = fix_beta_args)
Theta2_list <- list(Theta2 = diag(nrow(fixed)),
select = c(rep(FALSE, length(fixed) + 1),
rep(TRUE, nrow(fixed))))
Phi <- diag(c(0.5, 0.5))
example2 <- new("restrictions.1storder", factors = c(2L, 0L),
Domains = Domains, nvars = nrow(Domains),
model = "SEFA", method = "MLE", dof = 6L,
Phi = Phi, beta = beta_list, Theta2 = Theta2_list,
criteria = list(llik = FAiR:::FAiR_criterion_llik))
}
# 'restrictions' and 'starting.values' would typically be left unspecified!
sefa <- Factanal(covmat = ability.cov, factors = 2, model = "SEFA",
restrictions = example2, starting.values = starts2)
show(sefa)
summary(sefa)
stuff <- list() # output list for various methods, also works on efa and efa.rotated
stuff$model.matrix <- model.matrix(sefa) # sample correlation matrix
stuff$fitted <- fitted(sefa) # reproduced correlation with communalities on diagonal
stuff$residuals <- residuals(sefa) # difference between model.matrix and fitted
stuff$rstandard <- rstandard(sefa) # residual matrix rescaled to a correlation matrix
stuff$weights <- weights(sefa) # (scaled) approximate weights for residuals
stuff$influence <- influence(sefa) # weights * residuals
stuff$logLik <- logLik(sefa) # log-likelihood
stuff$BIC <- BIC(sefa) # BIC
stuff$profile <- profile(sefa) # profile plots of non-free parameters
plot(sefa) # advanced Scree plot
pairs(sefa) # Thurstone-style plot
Run the code above in your browser using DataLab