Package {qrfactor}


Type: Package
Title: Simultaneous Q-Mode and R-Mode Factor Analysis for Spatial Data
Version: 1.6
Date: 2026-08-10
Description: Performs Q-mode and R-mode factor analysis simultaneously on spatial and non-spatial data. A single function, qrfactor(), carries out principal component analysis, R-mode factor analysis, Q-mode factor analysis, simultaneous R- and Q-mode factor analysis, principal coordinate analysis and multidimensional scaling. Loadings and scores are returned from the fitted object, and the plot() method provides annotated biplots for combinations of eigenvectors, loadings and scores. Input may be supplied as an 'ESRI' shapefile, a delimited text file or a data frame.
License: GPL-2
URL: https://gowusu.github.io/qrfactor/, https://github.com/gowusu/qrfactor
BugReports: https://github.com/gowusu/qrfactor/issues
Depends: R (≥ 3.5.0)
Imports: methods, sp, cluster, mvoutlier, pvclust
Suggests: MASS, sf
Encoding: UTF-8
NeedsCompilation: no
Packaged: 2026-09-06 20:08:42 UTC; PC
Author: George Owusu [aut, cre]
Maintainer: George Owusu <owusugeorge@ug.edu.gh>
Repository: CRAN
Date/Publication: 2026-09-15 11:00:17 UTC

Simultaneous Q-Mode and R-Mode Factor Analysis

Description

The qrfactor function performs simultaneous Q-mode and R-mode factor analysis on spatial and non-spatial data.

Usage

qrfactor(source, layer='', var=NULL, type='', p="Yes", scale="sd", t='',
         nf=2, m=NULL, f=NULL, rotation=FALSE, ...)
## Default S3 method:
qrfactor(source, layer='', var=NULL, type='', p="Yes",
         scale="sd", t='', nf=2, m=NULL, f=NULL, rotation=FALSE, ...)
## S3 method for class 'qrfactor'
print(x,...)
## S3 method for class 'qrfactor'
summary(object,...)
## S3 method for class 'qrfactor'
plot(x,factors=c(1,2),type="loading",plot="",
cex="",pch=15,pos=3,main="",xlim="optimise",
ylim="optimise",abline=TRUE,legend="topright",legendvalues=c(100),
values=FALSE,nfactors=3,rowname=TRUE,par=c(1,2),verbose=FALSE,...)

Arguments

source

Folder path of the layer. Please quote the full folder path with forward slash "/". You can use R object as a source but you must set the layer parameter to "nofile"; see below

layer

The layer qrfactor in the folder that you want to work with. It is the file name of qrfactor. This is case sensitive, please. In case you want to use non spatial data such as ".csv", ".txt", "dat" or ".tab" insert the full file name as layer. In case of using R object as a source set "layer" parameter to "nofile"

var

The attributes or variables of the layer. In case of using non spatial data such as ".csv", ".txt", "dat" or ".tab" var are variables or column names

type

Types of plots 'mds'for multidimensional scale, 'coordinate' for principal coordinate analyse. Or The type of results one wants to plot. It takes "scores", "loadings", pca or eigenvectors. The deault is loadings.

p

Determine whether prediction must be done:"Yes". The scores are appended to the GIS data

t

The list of variables that one wants to transform eg. transform=c("gold","diamond")

scale

scale the data:"sd","pca","data". The default is "sd" that is the scaled data divided by the standard deviation. It can lso take "log" or "sqrt" and use the default "sd" for normal distribution transformation

rotation

Should the retained factors be rotated to simple structure? The default FALSE (equivalently "none") returns the classical unrotated solution; TRUE (equivalently "varimax") applies an orthogonal varimax rotation to the first nf factors. When rotation is requested the same orthogonal rotation is applied to the R-mode and Q-mode loadings, so both modes stay on one common set of axes and the scores, the combined loadings, the appended index columns and every biplot and map are rotated consistently. The raw eigenvectors, eigenvalues and PCA loadings (eigen.vector, eigen.value, pca) are never rotated. Rotation redistributes variance among the rotated factors, so their individual variance percentages change while their sum (and cumvariance) is preserved.

m

the the match field: the common variable on both the table and spatial data. This name must be identical to both sets of data

f

The full path of csv file and the name of csv eg. C:/Users/owusu/Documents/Rpackages/qrfactor14/inst/external/farms.csv

x

an object of class "qrfactor", i.e., a fitted model.

object

an object of class "qrfactor", i.e., a fitted model.

plot

The type of plots one desires. It takes "all" for all the 3 plots or "q" for q plot or "r" for r plot or 'qr' for both q and r plots

factors

list of factors one wants to plot. The default is factors=c(1,2). Please do not forget "c" in the list.

cex

A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default. It also accepts a vector of values which are recycled eg cex=c("gold")

nfactors

The number of factors to extract

pch

Either an integer specifying a symbol or a single character to be used as the default in plotting points.

pos

The position of text labels

main

Main title of the graph

xlim

x-coordinates of the axis eg xlim=c(-1.5,1.5)

ylim

y-coordinates of the axis eg ylim=c(-1.5,1.5)

abline

the intercept and slope, single values of straight lines through the current plot. eg. abline(-0.5,0.5)

legend

position of legend: it takes topright,topleft, bottomright,bottomleft, top, left, bottom, right

legendvalues

The values of the legend

values

Incase one wants to label the graph with another variables. eg. values=c("gold")

nf

The number of factors to extract

rowname

rownames of the data

par

the layout setteing in a form of list

verbose

logical; if TRUE, the analysis views (type = "cluster", "anova", "region", "admin", "diagnose") print their statistical tables (cluster means, ANOVA, Kruskal-Wallis, Tukey HSD, outliers) to the console. The default FALSE draws the plots silently, as R plot methods should. The plot() method also restores the user's par() settings on exit.

...

any other parameter can be added

Value

Objects of the class that basically list its elements

data

Original data for the model. All records must be numeric. It also accepts continous data

gisdata

GIS data for the model incase you use shape files

x.standard

it is the scale matrix of the original data

correlation

The correlation matrix for the data

eigen.value

eigen value of correlation matrix of the data

eigen.vector

eigen vector of correlation matrix of the data

diagonal.matrix

diagonal matrix of eigen vector

pca

pca loadings

pcascores

PCA scores

r.loading

R-mode loadings

q.loading

Q-mode loadings

loadings

combined loadings of R and Q on the same axis

q.scores

computed Q-mode scores

scores

combined R-mode and Q-mode scores on the same axis

rownames

row names of the loadings

variables

variables names of the loadings, of the original data

rotation

the rotation actually applied to the loadings: "varimax" or "none"

unrotated.r.loading

the R-mode loadings before rotation (identical to r.loading when rotation = FALSE)

unrotated.q.loading

the Q-mode loadings before rotation (identical to q.loading when rotation = FALSE)

Author(s)

George Owusu

References

Bivand, R. S., Pebesma, E. J., Gomez-Rubio, V. (2008) Applied Spatial Data Analysis with R. Springer Kabacoff, I. R. (2011) R in Action. Data Analysis and Graphics with R. Manning Publications Co Kaiser, H. F. (1958) The varimax criterion for analytic rotation in factor analysis. Psychometrika 23(3):187-200

Examples

# --- CSV / data-frame workflow (fast, always runs) ---
csv <- system.file("external", "Africanfreshwater.csv", package = "qrfactor")
var <- c("Domestic", "Industry", "Agricultur", "Resources",
         "withdrawal", "perCapitaW")

mod0 <- qrfactor(csv, var = var)   # classical unrotated solution (default)
mod0$r.loading
plot(mod0, rowname = "COUNTRY")

# opt in to a varimax rotation of the retained factors
rot <- qrfactor(csv, var = var, rotation = TRUE)
rot$rotation             # "varimax"
rot$unrotated.r.loading  # the unrotated loadings, same as mod0$r.loading


# per-cluster ANOVA / Kruskal-Wallis tables are printed only on request
plot(mod0, type = "cluster", verbose = TRUE)

# --- spatial workflow on the bundled shapefile (needs 'sf' and 'sp') ---
if (requireNamespace("sf", quietly = TRUE) &&
    requireNamespace("sp", quietly = TRUE)) {
  src   <- system.file("external", package = "qrfactor")
  layer <- "Africanfreshwater"
  mod1  <- qrfactor(src, layer, var = var)
  plot(mod1, rowname = "COUNTRY")

  # join a CSV table to the shapefile on a common key
  mod3 <- qrfactor(src, layer, var = var, m = "COUNTRY", f = csv)
  plot(mod3, rowname = "COUNTRY", cex = c("means"),
       legend = "topleft", values = c("cluster"), pch = 23)

  plot(mod1, type = "map")   # choropleth cascade of the factor indices
}


Internal factor analayses function

Description

It is for internal use only

Author(s)

George Owusu