3

I'm trying to add a function to manually (or by-hand, or judgmentally) rotate a factor loadings matrix from principal components analysis to the qmethod R package. By-hand rotation as in: one specifies the angle by which to rotate any given pair of factors. (Yeah it's weird, but it makes sense in Q Methodology.)

For now, I'm not looking for an interactive GUI (though that'd be real nice), but just a CLI interface where you press left or right and get updated plots and finally say OK.

The baseline is something like this from the legacy PQMethod program. enter image description here Here's a short video.

My current approach is to use psych::factor.rotate(), and to program a somewhat interactive (as in right, left, OK) CLI interface on top of that with updating plots.

Still, I wonder whether someone hasn't done this already.

I googled away, but came up short (couldn't even find a by-hand rotation procedure other than psych::factor.rotate().

Any suggestions?

Ps.: bonus if you have a suggestion for how to do this with an interactive GUI.

Pps.: anyone kind enough to add a qmethod tag to this? I don't have the necessary points.

maxheld
  • 3,963
  • 2
  • 32
  • 51
  • _"Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow..."_ – zero323 Jul 05 '15 at 20:03
  • 1
    @zero323 uh, really? Hope it's acceptable. In my defense, I *have* shown the steps I already took: *"Instead, describe the problem and what has been done so far to solve it."* Also, I don't think this will cause deluge of opinionated posts ("use this!", "use that!") – it's more a question of whether there *is* a package out there, and I'm just not using the right keyword or frame to find it. Anyway, thanks for policing – I know that's what keeps this site so great. – maxheld Jul 05 '15 at 20:08
  • @maxheld try if http://softwarerecs.stackexchange.com is the place to ask, check their help center if it allows this question – Marged Jul 05 '15 at 20:15
  • I am not sure but may be you are looking for manipulate package? – user227710 Jul 05 '15 at 20:20
  • 1
    @maxheld Well, personally I have mixed feelings about it. While asking for a recommendation is off-topic, recommendation as an answer is not. At the end of the day it is probably more about the way how you formulate the question than anything else. – zero323 Jul 05 '15 at 20:21

1 Answers1

1

I'd give manipulate a try - something in the veins of:

library(psych)
library(manipulate)
l <- l_orig <- unclass(loadings(principal(Harman.5, 2, scores=TRUE)))
manipulate( 
  { 
    if(rotateRight) 
      l <<- factor.rotate(l, angle, 1, 2)
    if (rotateLeft)
      l <<- factor.rotate(l, -1*angle, 1, 2)

    plot(l, xlim = c(-1, 1), ylim = c(-1, 1), xlab = 1, ylab = 2); abline(v = 0); abline(h = 0)
  }, 
  angle = slider(1, 90, step=1, initial = 1, label = "Angle"), 
  rotateRight = button(">"),
  rotateLeft = button("<")
)
l; l_orig

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • wow fantastic @lukeA – I'll definitely add that. Only downside: works only in RStudio, correct? – maxheld Jul 05 '15 at 21:57
  • 1
    yep, `manipulate` [provides](http://cran.r-project.org/web/packages/manipulate/manipulate.pdf) _"Interactive plotting functions for use within RStudio"_ – lukeA Jul 05 '15 at 22:03