Skip to content

Commit

Permalink
fix #17 indexDilemma output bug
Browse files Browse the repository at this point in the history
  • Loading branch information
markheckmann committed May 9, 2020
1 parent 2151cf9 commit 2abfd62
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 156 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# OpenRepGrid 0.1.14 (work in progress)

* correct indexDilemma output bug (#17, thanks to José Antonio González Del Puerto aka @MindCartographer)
* perturbation of grid ratings by perturbate and grids_perturbate
* indexPvaff now uses PCA of construct centered raw data in line with biplot (and Gridcor)
* allow blanks at end of line after tags in importTxt
Expand Down
53 changes: 53 additions & 0 deletions R/calc.r
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,59 @@ constructPca <- function(x, nfactors=3, rotate="varimax", method = "pearson" ,
return(pc)
}

# TODO
constructPca_new <- function(x, nfactors = 3, method = "raw", rotate = "none", trim = NA)
{
method <- match.arg(method,c("raw", "pearson", "kendall", "spearman"))

# PCA of construct centered raw data
if (method == "raw") {
input <- "matrix of construct centered raw data"
r <- ratings(x)
p <- stats::prcomp(t(r), center = TRUE, scale. = FALSE)
eigenvalues <- p$sdev^2
load_mat <- p$rotation
}


# PCA of construct correlations
if (method != "raw") {
input <- "construct correlation matrix"
rotate <- match.arg(rotate, c("none", "varimax", "promax", "cluster"))
if (!rotate %in% c("none", "varimax", "promax", "cluster"))
stop('only "none", "varimax", "promax" and "cluster" are possible rotations')

res <- constructCor(x, method = method, trim = trim) # calc inter constructs correations
pc <- principal(res, nfactors = nfactors, rotate = rotate) # do PCA
class(pc) <- c("constructPca", class(pc))

load_mat <- loadings(pc)
class(load_mat) <- "matrix"
eigenvalues <- pc$values
}



# attr(pc, "arguments") <- list(nfactors = nfactors, rotate = rotate, method = method)
return(pc)

# new structure
list(
input = input,
method = method,
nfactors = nfactors,
rotation = "none",
eigenvalues = eigenvalues,
loadings = load_mat


)
scale(t(r))^2 %>% sum

apply(load_mat, 2, function(x) sum(x^2))

}


#' Extract loadings from PCA of constructs.
#'
Expand Down
Loading

0 comments on commit 2abfd62

Please sign in to comment.