Revision 923d0cc1f43c36debbea1f1fb06e4de448065380 authored by Gilles Raiche on 31 August 2019, 09:11:55 UTC, committed by cran-robot on 31 August 2019, 09:11:55 UTC
1 parent 592b098
nCng.r
nCng <-
function(x, cor=TRUE, model="components", details=TRUE, ...) {
x <- eigenComputes(x, cor=cor, model=model, ...)
detail <- NULL
nlength <- 2
n <- length(x)
if (n < 6) stop("The number of variables must be at least 6.")
i <- 1
cng <- numeric(n-5)
while ((i+2*nlength+1) <= n) {
xa <- c(i:(i+nlength))
ya <- x[i:(i+nlength)]
compa <- lm(ya ~ xa)$coef[2]
xb <- c((i+1+nlength):(i+2*nlength+1))
yb <- x[(i+1+nlength):(i+1+2*nlength)]
compb <- lm(yb ~ xb)$coef[2]
cng[i] <- compb - compa
i <- i + 1
}
if (details == TRUE) detail <- data.frame(v=(1:(n-5)),values=x[1:(n-5)], cng)
cng <- as.numeric(which(cng==max(cng, na.rm=TRUE))+nlength)
res <- list(detail=detail, nFactors=c(cng))
class(res) <- c("nFactors","list")
return(res)
}
Computing file changes ...