Title: | General Recognition Theory |
---|---|
Description: | Functions to generate and analyze data for psychology experiments based on the General Recognition Theory. |
Authors: | Kazunaga Matsuki |
Maintainer: | Andy Wills <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.1 |
Built: | 2025-02-15 04:09:47 UTC |
Source: | https://github.com/cran/grt |
Functions to generate and analyze data for psychology experiments based on the General Recognition Theory.
This package is written based mostly on the GRT Toolbox for MATLAB by Alfonso-Reese (2006), although many functions have been renamed and modified from the original in order to make them more general and “R-like.”
The functions grtrnorm
and grtMeans
are
used for design categorization experiments and generating stimuli. The
functions glc
, gcjc
, gqc
,
and grg
are used for fitting the general linear
classifier, the general conjunctive classifier, the general quadratic
classifier, and the general random guessing model, respectively. The
glc
, gcjc
, and gqc
have plot
methods (plot.glc
, plot.gcjc
,
plot.gqc
, plot3d.glc
,
plot3d.gqc
).
For a complete list of functions, use library(help =
"catlearn")
.
Kazunaga Matsuki
Maintainer: Andy Wills [email protected]
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
Ashby, F. G., & Gott, R. E. (1988). Decision rules in the perception and categorization of multidimensional stimuli. Journal of Experimental Psychology: Learning, Memory, & Cognition, 14, 33-53.
Ashby, F. G. (1992) Multidimensional models of perception and cognition. Lawrence Erlbaum Associates.
Extracts the coefficients from the model object glc
, glcStruct
, or gcjc
.
## S3 method for class 'glc' coef(object, ...) ## S3 method for class 'glcStruct' coef(object, ...) ## S3 method for class 'gcjc' coef(object, ...)
## S3 method for class 'glc' coef(object, ...) ## S3 method for class 'glcStruct' coef(object, ...) ## S3 method for class 'gcjc' coef(object, ...)
object |
object of class |
... |
further arguments |
Both the object glc
and glcStruct
contain the parameters for the decision boundary in the form:
This function transforms and returns the coefficients of the function solved with respect the .
For the object gcjc
, a list of two coefficients (Intercepts) are returned.
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dl, fitdb=FALSE) abline(coef(fit.2dl), col = "red") abline(coef(fit.2dl$initpar)) fit.1dx <- update(fit.2dl, . ~ . -y) abline(v=coef(fit.1dx), col="green") fit.1dy <- update(fit.2dl, . ~ . -x) abline(h=coef(fit.1dy), col="blue")
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dl, fitdb=FALSE) abline(coef(fit.2dl), col = "red") abline(coef(fit.2dl$initpar)) fit.1dx <- update(fit.2dl, . ~ . -y) abline(v=coef(fit.1dx), col="green") fit.1dy <- update(fit.2dl, . ~ . -x) abline(h=coef(fit.1dy), col="blue")
Obtain the standardized distance between the two probability distributions, known as d' or sensitivity index.
dprime(x, category, response, par = list(), zlimit = Inf, type = c("SampleIdeal", "Observer")) dprimef(means, covs, noise=NULL)
dprime(x, category, response, par = list(), zlimit = Inf, type = c("SampleIdeal", "Observer")) dprimef(means, covs, noise=NULL)
x |
a data frame or matrix containing samples from two multivariate normal distributions. |
category |
a vector or factor of labels of populations to which the samples belong |
response |
a vector or factor specifying the participant's classification responses for each samples |
par |
object of class |
zlimit |
numeric. The z-scores (or discriminant scores) beyond the specified value will be truncated and replaced with that value. Default to |
type |
a character string specifying the type of d' to be returned. If |
means |
a list of numeric vectors containing the means of two distributions |
covs |
a matrix or a list of matrices containing the variance-covariance matrix of the two distributions |
noise |
numeric. perceptual and criterial noise expressed as standard deviation. Default to |
The function dprime
estimates d' from sample data sets, whereas the function dprimef
calculates it from population parameters.
In dprime
, if any parts of the argument par
are missing, the function will estimate an optimal linear decision bound from supplied x
and category
. The argument response
is not used if type
is SampleIdeal
.
Author of the original Matlab routines: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
data(subjdemo_2d) d2 <- subjdemo_2d db <- glcStruct(noise=10, coeffs=c(0.514,-0.857),bias=-0.000154) dprime(d2[,2:3], d2$category, d2$response, par = db, zlimit=7, type='SampleIdeal') mc <- mcovs(category ~ x + y, data=d2) dprimef(mc$means, mc$covs)
data(subjdemo_2d) d2 <- subjdemo_2d db <- glcStruct(noise=10, coeffs=c(0.514,-0.857),bias=-0.000154) dprime(d2[,2:3], d2$category, d2$response, par = db, zlimit=7, type='SampleIdeal') mc <- mcovs(category ~ x + y, data=d2) dprimef(mc$means, mc$covs)
Extract Akaike's An Information Criteria from a General Linear, Quadratic, or Conjunctive Classifier, or a General Random Guessing model
## S3 method for class 'glc' extractAIC(fit, scale, k = 2, ...) ## S3 method for class 'gqc' extractAIC(fit, scale, k = 2, ...) ## S3 method for class 'gcjc' extractAIC(fit, scale, k = 2, ...) ## S3 method for class 'grg' extractAIC(fit, scale, k = 2, ...)
## S3 method for class 'glc' extractAIC(fit, scale, k = 2, ...) ## S3 method for class 'gqc' extractAIC(fit, scale, k = 2, ...) ## S3 method for class 'gcjc' extractAIC(fit, scale, k = 2, ...) ## S3 method for class 'grg' extractAIC(fit, scale, k = 2, ...)
fit |
object of class |
scale |
unused argument |
k |
numeric specifying the penalty per parameter to be used in calculating AIC. Default to 2. |
... |
further arguments (currently not used). |
As with the default method, the criterion used is
where is the likelihood and
is the degrees
of freedom (i.e., the number of free parameters) of
fit
.
A numeric vector of length 2 including:
df |
the degrees of freedom for the fitted model |
AIC |
the Akaike's Information Criterion for |
data(subjdemo_2d) #fit a 2d suboptimal model fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) extractAIC(fit.2dl)
data(subjdemo_2d) #fit a 2d suboptimal model fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) extractAIC(fit.2dl)
Draw a gray-scale Gabor Patch
gaborPatch(sf, theta = 0, rad = (theta * pi)/180, pc = 1, sigma = 1/6, psi = 0, grating = c("cosine", "sine"), npoints = 100, trim = 0, trim.col = .5, ...)
gaborPatch(sf, theta = 0, rad = (theta * pi)/180, pc = 1, sigma = 1/6, psi = 0, grating = c("cosine", "sine"), npoints = 100, trim = 0, trim.col = .5, ...)
sf |
number of cycles per image. |
theta |
orientation in degree. See ‘Details’ |
rad |
orientation in radian |
pc |
a fraction (0 to 1) specifying the peak contrast of the Gabor |
sigma |
the standard deviation of the Gaussian mask. Either a single numeric or a numeric vector of length 2. |
psi |
phase offset in radian |
grating |
type of grating to be used. Default to ‘cosine’. |
npoints |
number of points per line used to draw the patch. |
trim |
Gaussian values smaller than the specified value should be trimmed. |
trim.col |
gray level of the trimmed part of the image, between 0 (‘black’) and 1 (‘white’). Default to .5 (‘gray’) Setting it to any other value or |
... |
additional parameters for |
The arguments theta
and rad
is the same thing but in different units. If both are supplied, rad
takes the precedence.
invisibly returns the matrix of the plotted values.
This function is written just for fun; it is not optimized for speed or for performance.
Fredericksen, R. E., Bex, P. J., & Verstraten, F. A. J. (1997). How Big is a Gabor and Why Should We Care? Journal of the Optical Society of America A. 14, 1–12.
Gabor Filter. (2010, June 5). In Wikipedia, the free encyclopedia. Retrieved July 7, 2010, from http://en.wikipedia.org/wiki/Gabor_filter
# An imitation of Fredericksen et al.'s (1997) Fig 1. # that demonstrate the relation between peak contrast # and perceived size of the Gabor op <- par(mfcol = c(3, 3), pty = "m", mai = c(0,0,0,0)) for(i in c(.85, .21, .06)){ for(j in c(1/6, 1/7, 1/8)){ gaborPatch(20, pc = i, sigma = j) } } par(op) ## Not run: # a typical plot of the stimuli and category structure # often seen in artificial category-learning literatures. m <- list(c(268, 157), c(332, 93)) covs <- matrix(c(4538, 4351, 4351, 4538), ncol = 2) II <- grtrnorm(n = 40, np = 2, means = m, covs = covs, clip.sd = 4, seed = 1234) II$sf <- .25+(II$x1/50) II$theta <- II$x2*(18/50) plot(II[,2:3], xlim = c(-100,600), ylim = c(-200,500), pch = 21, bg = c("white","gray")[II$category]) abline(a = -175, b = 1) library(Hmisc) idx <- c(20, 31, 35, 49, 62) xpos <- c(0, 100, 300, 350, 550) ypos <- c(50, 300, 420, -120, 50) for(i in 1:5) { j = idx[i] segments(x0=II[j,"x1"], y0=II[j,"x2"], x1=xpos[i], y1=ypos[i]) subplot(gaborPatch(sf=II[j,"sf"], theta=II[j,"theta"]), x=xpos[i], y=ypos[i]) } ## End(Not run)
# An imitation of Fredericksen et al.'s (1997) Fig 1. # that demonstrate the relation between peak contrast # and perceived size of the Gabor op <- par(mfcol = c(3, 3), pty = "m", mai = c(0,0,0,0)) for(i in c(.85, .21, .06)){ for(j in c(1/6, 1/7, 1/8)){ gaborPatch(20, pc = i, sigma = j) } } par(op) ## Not run: # a typical plot of the stimuli and category structure # often seen in artificial category-learning literatures. m <- list(c(268, 157), c(332, 93)) covs <- matrix(c(4538, 4351, 4351, 4538), ncol = 2) II <- grtrnorm(n = 40, np = 2, means = m, covs = covs, clip.sd = 4, seed = 1234) II$sf <- .25+(II$x1/50) II$theta <- II$x2*(18/50) plot(II[,2:3], xlim = c(-100,600), ylim = c(-200,500), pch = 21, bg = c("white","gray")[II$category]) abline(a = -175, b = 1) library(Hmisc) idx <- c(20, 31, 35, 49, 62) xpos <- c(0, 100, 300, 350, 550) ypos <- c(50, 300, 420, -120, 50) for(i in 1:5) { j = idx[i] segments(x0=II[j,"x1"], y0=II[j,"x2"], x1=xpos[i], y1=ypos[i]) subplot(gaborPatch(sf=II[j,"sf"], theta=II[j,"theta"]), x=xpos[i], y=ypos[i]) } ## End(Not run)
Fit a general conjunctive classifier.
gcjc(formula, data, category, par, config = 1, zlimit = Inf, fixed = list(), equal.noise = TRUE, opt = c("nlminb", "optim"), lower=-Inf, upper=Inf, control=list())
gcjc(formula, data, category, par, config = 1, zlimit = Inf, fixed = list(), equal.noise = TRUE, opt = c("nlminb", "optim"), lower=-Inf, upper=Inf, control=list())
formula |
A formula of the form |
data |
A data frame from which variables specified in |
category |
(Optional.) A factor specifying the true category membership of the stimuli. |
par |
object of class |
config |
A numeric value specifying the location of the conjunctive category in relation to the category bounds. The value 1 indicates the category is on the top right (set as default), 2 indicates the top left, 3 indicates bottom left, and 4 indicates the bottom right. |
zlimit |
numeric. The z-scores (or discriminant scores) beyond the specified value will be truncated. Default to |
fixed |
A named list of logical vectors specifying whether each of |
equal.noise |
logical. If set to |
opt |
A character string specifying the optimizer to be used: either |
lower , upper
|
Bounds on the parameters. see ‘Details’ for default values. |
control |
A list of control parameters passed to the internal optimization function. See ‘Details’ of |
If par
is not fully specified in the argument, the function attempts to calculate the initial parameter values based on means by category or by response.
The default lower and upper values are selected based on the range of the data
input so that the decision bound is found within the range of the data and convergence can be reached.
object of the class gcjc
, i.e., a list containing the following components:
terms |
the |
call |
the matched call. |
model |
the design matrix used to fit the model. |
category |
the category vector as specified in the input. |
initpar |
the initial parameter used to fit the model. |
par |
the fitted parameter. |
logLik |
the log-likelihood at convergence. |
Ashby, F. G. (1992) Multidimensional models of perception and cognition. Lawrence Erlbaum Associates.
glc
,
logLik.gcjc
,
coef.gcjc
,
plot.gcjc
data(subjdemo_cj) m.cj <- gcjc(response ~ x1 + x2, data=subjdemo_cj, config=2, category=subjdemo_cj$category, zlimit=7)
data(subjdemo_cj) m.cj <- gcjc(response ~ x1 + x2, data=subjdemo_cj, config=2, category=subjdemo_cj$category, zlimit=7)
A list of model parameters that specify a conjunctive decision bound, containing noise
, coeffs
, and bias
.
gcjcStruct(noise, bias, config=c(1,2,3,4))
gcjcStruct(noise, bias, config=c(1,2,3,4))
noise |
a positive non-zero numeric. |
bias |
numeric vector corresponding to the intercepts of the bounds |
config |
A numeric value specifying the location of the conjunctive category in relation to the category bounds. The value 1 indicates the category is on the top right (set as default), 2 indicates the top left, 3 indicates bottom left, and 4 indicates the bottom right. |
object of class gcjcStruct
, which is a list of a named list containing noise
, coeffs
, and bias
.
gcjc
,
coef.glcStruct
,
logLik.glcStruct
params <- gcjcStruct(noise=10, bias=c(100, 200), config=1)
params <- gcjcStruct(noise=10, bias=c(100, 200), config=1)
Fit a general linear classifier (a.k.a. linear decison-bound model).
glc(formula, data, category, par = list(), zlimit = Inf, covstruct=c("unstructured", "scaledIdentity", "diagonal", "identity"), fixed = list(), opt = c("nlminb", "optim"), lower=-Inf, upper=Inf, control=list())
glc(formula, data, category, par = list(), zlimit = Inf, covstruct=c("unstructured", "scaledIdentity", "diagonal", "identity"), fixed = list(), opt = c("nlminb", "optim"), lower=-Inf, upper=Inf, control=list())
formula |
A formula of the form |
data |
A data frame from which variables specified in |
category |
(Optional.) A factor specifying the true category membership of the stimuli. |
par |
object of class |
zlimit |
numeric. The z-scores (or discriminant scores) beyond the specified value will be truncated. Default to |
covstruct |
An optional character string. Only used when the initial parameters are not fully specified. see |
fixed |
A named list of logical vectors specifying whether each of |
opt |
A character string specifying the optimizer to be used: either |
lower , upper
|
Bounds on the parameters. see ‘Details’ for default values. |
control |
A list of control parameters passed to the internal optimization function. See ‘Details’ of |
If par
is not fully specified in the argument, the function attempts to calculate the initial parameter values by internally calling the functions mcovs
and ldb
. If category
is also not specified, the response specified in the formula
is used as the grouping factor in mcovs
.
The default lower and upper values vary depending on the dimension of the model (i.e., the number of variables in the right hand side of formula
). In all cases, default lower and upper values for the noise
parameter is .001 and 500 respectively. In cases when an one-dimensional model is fitted, lower and upper bounds for the bias
parameters are selected based on the range of the data
input so that the decision bound is found within the reasonable range of the data and convergence can be reached. In all other cases, coeffs
and bias
has no limits.
When an one-dimensional model is being fit, fixed$coeffs
always becomes TRUE
.
object of the class glc
, i.e., a list containing the following components:
terms |
the |
call |
the matched call. |
model |
the design matrix used to fit the model. |
category |
the category vector as specified in the input. |
initpar |
the initial parameter used to fit the model. |
par |
the fitted parameter. |
logLik |
the log-likelihood at convergence. |
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
Ashby, F. G., & Gott, R. E. (1988). Decision rules in the perception and categorization of multidimensional stimuli. Journal of Experimental Psychology: Learning, Memory, & Cognition, 14, 33-53.
Ashby, F. G. (1992) Multidimensional models of perception and cognition. Lawrence Erlbaum Associates.
gqc
,
ldb
,
logLik.glc
,
coef.glc
,
predict.glc
,
scale.glc
,
plot.glc
,
plot3d.glc
data(subjdemo_2d) d2 <- subjdemo_2d #fit a 2d suboptimal model fit.2dl <- glc(response ~ x + y, data=d2, category=d2$category, zlimit=7) #fit a 1d model (on the dimention 'y') on the same dataset fit.1dy <- glc(response ~ y, data=d2, category=d2$category, zlimit=7) #or using update() #fit.1dy <- update(fit.2dl, . ~ . -x) #fit a 2d optimal model fit.2dlopt <- glc(response ~ x + y, data=d2, category=d2$category, zlimit=7, fixed=list(coeffs=TRUE, bias=TRUE)) #calculate AIC and compare AIC(fit.2dl, fit.1dy, fit.2dlopt)
data(subjdemo_2d) d2 <- subjdemo_2d #fit a 2d suboptimal model fit.2dl <- glc(response ~ x + y, data=d2, category=d2$category, zlimit=7) #fit a 1d model (on the dimention 'y') on the same dataset fit.1dy <- glc(response ~ y, data=d2, category=d2$category, zlimit=7) #or using update() #fit.1dy <- update(fit.2dl, . ~ . -x) #fit a 2d optimal model fit.2dlopt <- glc(response ~ x + y, data=d2, category=d2$category, zlimit=7, fixed=list(coeffs=TRUE, bias=TRUE)) #calculate AIC and compare AIC(fit.2dl, fit.1dy, fit.2dlopt)
A named list of model parameters that specify a linear decision bound, containing noise
, coeffs
, and bias
.
glcStruct(noise, coeffs, bias)
glcStruct(noise, coeffs, bias)
noise |
a positive non-zero numeric. |
coeffs |
vector. the length of the |
bias |
numeric. |
object of class glcStruct
, i.e., a named list containing noise
, coeffs
, and bias
. Returned values are normalized, such that each value are divided by the euclidean norm of the coeffs
vector, and the sum of coeffs^2
is 1.
glc
,
coef.glcStruct
,
logLik.glcStruct
,
old2new_par
,
new2old_par
params <- glcStruct(noise=10, coeffs=c(1, -1), bias=0)
params <- glcStruct(noise=10, coeffs=c(1, -1), bias=0)
Fit a general quadratic classifier (a.k.a. quadratic decison-bound model).
gqc(formula, data, category, par = list(), zlimit = Inf, fixed = list(), opt = c("nlminb", "optim"), lower=-Inf, upper=Inf, control=list())
gqc(formula, data, category, par = list(), zlimit = Inf, fixed = list(), opt = c("nlminb", "optim"), lower=-Inf, upper=Inf, control=list())
formula |
A formula of the form |
data |
A data frame from which variables specified in |
category |
(Optional.) A factor specifying the true category membership of the stimuli. |
par |
object of class |
zlimit |
numeric. The z-scores (or discriminant scores) beyond the specified value will be truncated. Default to |
fixed |
A named list of logical vectors specifying whether each of |
opt |
A character string specifying the optimizer to be used: either |
lower , upper
|
Bounds on the parameters. Default values of lower and upper are |
control |
A list of control parameters passed to the optimizer. See ‘Details’ of |
If par
is not fully specified in the argument, the function attempts to calculate the initial parameter values by internally calling the functions mcovs
and qdb
. The response specified in the formula
is used as the grouping factor in mcovs
.
object of class gqc
, i.e., a list containing the following components:
terms |
the |
call |
the matched call. |
model |
the design matrix used to fit the model. |
category |
the category vector as specified in the input. |
initpar |
the initial parameter used to fit the model. |
par |
the fitted parameter. |
logLik |
the log-likelihood at convergence. |
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
Ashby, F. G., & Gott, R. E. (1988). Decision rules in the perception and categorization of multidimensional stimuli. Journal of Experimental Psychology: Learning, Memory, & Cognition, 14, 33-53.
Ashby, F. G. (1992) Multidimensional models of perception and cognition. Lawrence Erlbaum Associates.
glc
,
qdb
,
logLik.gqc
,
logLik.gqcStruct
,
plot.gqc
,
plot3d.gqc
data(subjdemo_2d) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7)
data(subjdemo_2d) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7)
A named list of model parameters that specify a quadratic decision bound, containing pnoise
, cnoise
, coeffs
, and bias
.
gqcStruct(pnoise, cnoise, coeffs, bias)
gqcStruct(pnoise, cnoise, coeffs, bias)
pnoise |
a positive non-zero numeric. |
cnoise |
a positive non-zero numeric. |
coeffs |
a vector. The |
bias |
numeric. |
object of class gqcStruct
, i.e., a named list containing pnoise
, cnoise
, coeffs
, and bias
.
params <- gqcStruct(pnoise=10, cnoise=100, coeffs=c(1,2,3,4,5), bias=6)
params <- gqcStruct(pnoise=10, cnoise=100, coeffs=c(1,2,3,4,5), bias=6)
General Random Guessing model
grg(response, fixed = FALSE, k = 2)
grg(response, fixed = FALSE, k = 2)
response |
A vector containing participant's classification responses. |
fixed |
logical. If |
k |
numeric. the penalty per parameter to be used in calculating AIC. Default to 2. |
The function assumes that there are two categories (e.g, ‘A’ and ‘B’) to which each stimulus belongs.
Fixed Random Guessing model assumes that participant responded randomly without response bias; for each stimulus, probability of responding ‘A’ and ‘B’ is .5. There are no free parameters in this model (i.e., df = 0).
General Random Guessing model assumes that participants responded randomly but is biased toward one response. The model estimates the response bias (df = 1).
object of class grg
, which is a list object containing:
par |
the fixed or estimated response bias |
logLik |
the log-likelihood of the model |
AIC |
Akaike's An Information Criterion for the fitted model |
Ashby, F. G., & Crossley, M. J. (2010). Interactions between declarative and procedural-learning categorization systems. Neurobiology of Learning and Memory, 94, 1-12.
data(subjdemo_2d) fit.grand <- grg(subjdemo_2d$response, fixed=FALSE) fit.frand <- grg(subjdemo_2d$response, fixed=TRUE)
data(subjdemo_2d) fit.grand <- grg(subjdemo_2d$response, fixed=FALSE) fit.frand <- grg(subjdemo_2d$response, fixed=TRUE)
Obtain means of two multivariate normal populations having the specified covariance structure and centroid, and with which classification based on the optimal decision boundary satisfies the supplied probability of correct classification.
grtMeans(covs, centroid, optldb, p.correct, initd = 5, stepsize = 1)
grtMeans(covs, centroid, optldb, p.correct, initd = 5, stepsize = 1)
covs |
a matrix or a list of matrices specifying the covariance matrices of the variables. Each matrix should be positive-definite and symmetric. |
centroid |
a vector specifying the center of the two population means |
optldb |
object of class |
p.correct |
a numeric value between 0 to 1 that specifies the optimal classification performance in terms of probability of correct classification given the decision boundary |
initd |
numeric. An initial distance between the means of two populations. Default is 5. |
stepsize |
a positive numeric specifying step size to be taken when searching for the means. Default is 1. |
means |
a list of two vectors specifying the means of two populations. |
covs |
a matrix of (averaged) covariance. |
p.correct |
the obtained probability of correct classification. |
Author of the original Matlab routine ‘Design2dGRTexp’: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
foo <- grtMeans(diag(c(625,625)), centroid=c(200, 200*.6), optldb=c(.6,-1,0), p.correct=.85)
foo <- grtMeans(diag(c(625,625)), centroid=c(200, 200*.6), optldb=c(.6,-1,0), p.correct=.85)
Generate one or more samples from the two or more specified multivariate normal distributions.
grtrnorm(n, np = 2, means = list(rep(0,np), rep(0,np)), covs = diag(rep(1,np)), clip.sd = Inf, tol = 1e-6, empirical = TRUE, seed = NULL, response.acc = NULL)
grtrnorm(n, np = 2, means = list(rep(0,np), rep(0,np)), covs = diag(rep(1,np)), clip.sd = Inf, tol = 1e-6, empirical = TRUE, seed = NULL, response.acc = NULL)
n |
the number of samples per population required |
np |
the number of populations to be sampled from |
means |
a list of vectors specifying the means of the variable for each populations |
covs |
a matrix or a list of matrices specifying the covariance matrices of the variables. Each matrix should be positive-definite and symmetric. |
clip.sd |
an integer specifying the cutoff value of standard score. The standard score of a generated sample exceeding this value should be truncated. Default to |
tol |
tolerance (relative to largest variance) for numerical lack of positive-definiteness in |
empirical |
logical. If true, |
seed |
an integer internally supplied as |
response.acc |
an optional numeric value between 0 and 1, specifying the classification accuracy of a hypothetical observer. See ‘Details’. Default to |
This function is essentially a wrapper to the mvrnorm
function in MASS
package.
If the optional response.acc
argument is supplied, hypothetical random classification responses with specified accuracy will be generated.
a data frame containing a column of numeric category labels and column(s) of sampled values for each variable, and optionally, a column of hypothetical responses.
Author of the original Matlab routines: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
m <- list(c(268,157), c(332, 93)) covs <- matrix(c(4538, 4351, 4351, 4538), ncol=2) II <- grtrnorm(n=80, np=2, means=m, covs=covs) m <- list(c(283,98),c(317,98),c(283,152),c(317,152)) covs <- diag(75, ncol=2, nrow=2) CJ <- grtrnorm(n=c(8,16,16,40), np=4, means=m, covs=covs) CJ$category <- c(1,1,1,2)[CJ$category]
m <- list(c(268,157), c(332, 93)) covs <- matrix(c(4538, 4351, 4351, 4538), ncol=2) II <- grtrnorm(n=80, np=2, means=m, covs=covs) m <- list(c(283,98),c(317,98),c(283,152),c(317,152)) covs <- diag(75, ncol=2, nrow=2) CJ <- grtrnorm(n=c(8,16,16,40), np=4, means=m, covs=covs) CJ$category <- c(1,1,1,2)[CJ$category]
Find coefficients of the ideal linear decision boundary given the means and covariance of two categories.
ldb(means, covs, covstruct = c("unstructured", "scaledIdentity", "diagonal", "identity"), noise = 10)
ldb(means, covs, covstruct = c("unstructured", "scaledIdentity", "diagonal", "identity"), noise = 10)
means |
a list of vectors containing means of two distributions. |
covs |
a matrix or a list of matrix containing the covariance matrix common to the two distributions. |
covstruct |
character. If |
noise |
numeric value. See Details. Default to 10. |
The order of vectors in the list means
matters as the sign of coeffs
and bias
in the output will be reversed.
The argument noise
is only for convenience; the supplied value is simply bypassed to the output for the subsequent use, i.e., as object of class glcStruct
.
The object of class glcStruct
Author of the original Matlab routine ‘lindecisbnd’: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(625, 625)) foo <- ldb(means=m, covs=covs)
m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(625, 625)) foo <- ldb(means=m, covs=covs)
Estimates the probability of correct classification under the condition in which the optimal linear decision boundary is used to categorize the samples from two multivariate normal populations with the specified parameters
ldb.p.correct(means, covs, noise = 0)
ldb.p.correct(means, covs, noise = 0)
means |
a list of vectors, each specifying the means of a multivariate normal population. |
covs |
a matrix or a list of matrices specifying the covariance matrix of the each multivariate normal population. If a list is given and length(covs) > 2, an unweighted average of the matrices is used. |
noise |
an optional numeric value specifying the noise associated with the decision bound. Default to 0. |
Author of the original Matlab routine ‘linprobcorr’: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
foo <- grtMeans(diag(c(625,625)), centroid=c(200, 200*.6), optldb=c(.6,-1,0), p.correct=.85) ldb.p.correct(foo$means, foo$covs)
foo <- grtMeans(diag(c(625,625)), centroid=c(200, 200*.6), optldb=c(.6,-1,0), p.correct=.85) ldb.p.correct(foo$means, foo$covs)
Add a quadratic decision boundary line through the current plot.
## S3 method for class 'gqcStruct' lines(x, xlim = c(0,1), ylim = c(0,1), npoints = 100, col = "black", ...)
## S3 method for class 'gqcStruct' lines(x, xlim = c(0,1), ylim = c(0,1), npoints = 100, col = "black", ...)
x |
object of class |
xlim |
the x limits of the plot. Default to |
ylim |
the y limits of the plot. Default to |
npoints |
numeric. number of points per dimension used to plot the decision bound. Default is 100. |
col |
the color to be used for the line |
... |
further arguments. |
an invisible list of x- and y-coordinates of the line:
x |
a vector of x-coordinates of the line |
y |
a vector of y-coordinates of the line |
data(subjdemo_2d) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dq, fitdb=FALSE, initdb=FALSE) lines(fit.2dq$par, xlim=c(0,400), ylim=c(0,400), col="red") lines(fit.2dq$initpar, xlim=c(0,400), ylim=c(0,400), col="blue")
data(subjdemo_2d) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dq, fitdb=FALSE, initdb=FALSE) lines(fit.2dq$par, xlim=c(0,400), ylim=c(0,400), col="red") lines(fit.2dq$initpar, xlim=c(0,400), ylim=c(0,400), col="blue")
Extract the log-likelihood of the fitted general linear or conjunctive classifier model.
## S3 method for class 'glc' logLik(object, ...) ## S3 method for class 'gcjc' logLik(object, ...)
## S3 method for class 'glc' logLik(object, ...) ## S3 method for class 'gcjc' logLik(object, ...)
object |
object of class |
... |
further arguments (currently unused) |
The log-likelihood for the general linear or conjunctive classifier represented by the estimated parameters in object
This function is intended for indirect internal use by functions such as AIC
.
To obtain the log-likelihood of the fitted model applied to new dataset, use logLik.glcStruct
or logLik.gcjcStruct
glc
,
logLik.glcStruct
,
gcjc
,
logLik.gcjcStruct
data(subjdemo_2d) fit <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) logLik(fit)
data(subjdemo_2d) fit <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) logLik(fit)
Calculate the log-likelihood of the general linear or conjunctive classifier model applied to a data set.
## S3 method for class 'glcStruct' logLik(object, response, x, zlimit = Inf, ...) ## S3 method for class 'gcjcStruct' logLik(object, response, x, zlimit = Inf, ...)
## S3 method for class 'glcStruct' logLik(object, response, x, zlimit = Inf, ...) ## S3 method for class 'gcjcStruct' logLik(object, response, x, zlimit = Inf, ...)
object |
object of class |
response |
a vector of classification responses used to calculate the log-likelihood of the model. |
x |
a matrix or dataframe containing values for each stimulus dimensions. |
zlimit |
integer. Used to truncate the z-scores whose absolute values are greater than |
... |
further arguments (currently unused) |
The log-likelihood for the general linear or conjunctive classifier described by object
fitted against the dataset given by response
and x
.
The value of attributes, attr(, "df")
(degrees of freedom) is calculated based on the assumption that all the parameters in object
are free to vary.
gqc
,
gqcStruct
,
logLik.glc
,
logLik.gcjc
m <- list(c(187, 142), c(213, 98)) covs <- diag(625, ncol=2, nrow=2) db <- ldb(means=m, covs=covs, noise=10) data(subjdemo_2d) logLik(db, subjdemo_2d$response, x=subjdemo_2d[2:3], zlimit=7)
m <- list(c(187, 142), c(213, 98)) covs <- diag(625, ncol=2, nrow=2) db <- ldb(means=m, covs=covs, noise=10) data(subjdemo_2d) logLik(db, subjdemo_2d$response, x=subjdemo_2d[2:3], zlimit=7)
Extract the log-likelihood of the fitted general quadratic classifier model.
## S3 method for class 'gqc' logLik(object, ...)
## S3 method for class 'gqc' logLik(object, ...)
object |
object of class |
... |
further arguments (currently unused) |
The log-likelihood for the general quadratic classifier represented by the estimated parameters in object
This function is intended for indirect internal use by functions such as AIC
.
To obtain the log-likelihood of the fitted model applied to new dataset, use logLik.gqcStruct
Calculate the log-likelihood of the general quadratic classifier model applied to a data set.
## S3 method for class 'gqcStruct' logLik(object, response, x, zlimit = Inf, ...)
## S3 method for class 'gqcStruct' logLik(object, response, x, zlimit = Inf, ...)
object |
object of class |
response |
a vector of classification responses used to calculate the log-likelihood of the gqc model. |
x |
a matrix or dataframe containing values for each stimulus dimensions. |
zlimit |
integer. Used to truncate the z-scores whose absolute values are greater than |
... |
further arguments (currently unused) |
The log-likelihood for the general quadratic classifier described by object
fitted against the dataset given by response
and x
.
The value of attributes, attr(, "df")
(degrees of freedom) is calculated based on the assumption that all the parameters in object
are free to vary.
m <- list(c(187, 142), c(213, 98)) covs <- list(diag(625, ncol=2, nrow=2), diag(600, ncol=2, nrow=2)) db <- qdb(means=m, covs=covs) data(subjdemo_2d) logLik(db, subjdemo_2d$response, x=subjdemo_2d[2:3], zlimit=7)
m <- list(c(187, 142), c(213, 98)) covs <- list(diag(625, ncol=2, nrow=2), diag(600, ncol=2, nrow=2)) db <- qdb(means=m, covs=covs) data(subjdemo_2d) logLik(db, subjdemo_2d$response, x=subjdemo_2d[2:3], zlimit=7)
Calculate sample means and covariance(s) of multivariate data
## Default S3 method: mcovs(x, grouping, pooled=TRUE, ...) ## S3 method for class 'formula' mcovs(formula, data, pooled=TRUE, ...)
## Default S3 method: mcovs(x, grouping, pooled=TRUE, ...) ## S3 method for class 'formula' mcovs(formula, data, pooled=TRUE, ...)
formula |
A formula in the form of |
data |
Data frame from which variables specified in |
x |
data frame or Matrix containing sample values. |
grouping |
a factor specifying the population to which the samples in |
pooled |
logical. If |
... |
further arguments |
A list containing:
N |
total number of samples. |
counts |
number of samples per groups. |
lev |
levels of the |
means |
a named list of vectors specifying the means for each group. Named according to |
covs |
a named list of variance-covarinace matrix(es). Named as |
Converts the glcStruct in ‘new’ format to ‘old’ format whereby a vector of angle
is converted to coeffs
.
new2old_par(x) angle2cart(angle)
new2old_par(x) angle2cart(angle)
x |
object of class |
angle |
vector. |
For new2old_par
, object of class glcStruct
.
For angle2cart
, vector.
Author of the original Matlab routines: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
old2new_par
cart2angle
glcStruct
m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(625, 625)) foo <- ldb(means=m, covs=covs) bar <- old2new_par(foo) new2old_par(bar) angle2cart(bar$angle)
m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(625, 625)) foo <- ldb(means=m, covs=covs) bar <- old2new_par(foo) new2old_par(bar) angle2cart(bar$angle)
Converts glcStruct in the 'old' to 'new' format for more efficient optimization where coeffs
vectors are converted to a vector of angle
with length of (coeffs) - 1
old2new_par(x) cart2angle(cart)
old2new_par(x) cart2angle(cart)
x |
object of class |
cart |
vector. |
For old2new_par
, object of class glcStruct
.
For cart2angle
, vector.
Author of the original Matlab routines: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(625, 625)) foo <- ldb(means=m, covs=covs) old2new_par(foo) cart2angle(foo$coeffs)
m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(625, 625)) foo <- ldb(means=m, covs=covs) old2new_par(foo) cart2angle(foo$coeffs)
Plot the fitted data set and decision boundary.
## S3 method for class 'gcjc' plot(x, fitdb = TRUE, initdb = FALSE, xlim = NULL, ylim = NULL, bg, pch, ...)
## S3 method for class 'gcjc' plot(x, fitdb = TRUE, initdb = FALSE, xlim = NULL, ylim = NULL, bg, pch, ...)
x |
object of class |
fitdb |
logical. If |
initdb |
logical. If |
xlim |
the x limits of the plot |
ylim |
the y limits of the plot |
bg |
the background color to be used for points. Default is |
pch |
the symbols to be used as points. Default is |
... |
further arguments. |
This function produces a scatter plot of data matrix in the x
and (optionally) decision boundary specified within (i.e., x$par
and/or x$initpar
).
m <- list(c(100,200),c(100,100),c(200,100),c(200,200)) covs <- diag(30^2, ncol=2, nrow=2) set.seed(1) CJ <- grtrnorm(n=c(50,20,10,20), np=4, means=m, covs=covs) CJ$category <- c(1,2,2,2)[CJ$category] #create ramdom responses with 80% accuracy CJ$response <- CJ$category set.seed(1) incorrect <- sample(1:100, size=20) CJ$response[incorrect] <- abs(CJ$response[incorrect] - 3) #now fit the model m.cj <- gcjc(response ~ x1 + x2, data=CJ, config=2, category=CJ$category, zlimit=7) plot(m.cj)
m <- list(c(100,200),c(100,100),c(200,100),c(200,200)) covs <- diag(30^2, ncol=2, nrow=2) set.seed(1) CJ <- grtrnorm(n=c(50,20,10,20), np=4, means=m, covs=covs) CJ$category <- c(1,2,2,2)[CJ$category] #create ramdom responses with 80% accuracy CJ$response <- CJ$category set.seed(1) incorrect <- sample(1:100, size=20) CJ$response[incorrect] <- abs(CJ$response[incorrect] - 3) #now fit the model m.cj <- gcjc(response ~ x1 + x2, data=CJ, config=2, category=CJ$category, zlimit=7) plot(m.cj)
Plot the fitted data set and linear decision boundary.
## S3 method for class 'glc' plot(x, fitdb = TRUE, initdb = FALSE, xlim = NULL, ylim = NULL, bg, pch, ...)
## S3 method for class 'glc' plot(x, fitdb = TRUE, initdb = FALSE, xlim = NULL, ylim = NULL, bg, pch, ...)
x |
object of class |
fitdb |
logical. If |
initdb |
logical. If |
xlim |
the x limits of the plot |
ylim |
the y limits of the plot |
bg |
the background color to be used for points. Default is |
pch |
the symbols to be used as points. Default is |
... |
further arguments. |
This function produces a scatter plot of data matrix in the x
and (optionally) decision boundary specified within (i.e., x$par
and/or x$initpar
).
The look of the plot differs depending on the dimension of the model. If the dimension is 1, the model matrix is plotted on the y-axis, and category vector (as in x$category
) is plotted on the x axis. If the dimension is 2, scatter plot of the model matrix is plotted. If the dimension is 3, plot3d.glc
is called to create a 3D scatter plot. If the dimension is greater than 3, an error message will be returned.
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dl) #if one wants to plot decision bounds in # colors different from the defaults plot(fit.2dl, fitdb=FALSE) abline(coef=coef(fit.2dl$par), col="orange") abline(coef=coef(fit.2dl$initpar), col="purple")
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dl) #if one wants to plot decision bounds in # colors different from the defaults plot(fit.2dl, fitdb=FALSE) abline(coef=coef(fit.2dl$par), col="orange") abline(coef=coef(fit.2dl$initpar), col="purple")
Plot the fitted data set and quadratic decision boundary.
## S3 method for class 'gqc' plot(x, fitdb = TRUE, initdb = FALSE, xlim = NULL, ylim = NULL, bg, pch, npoints = 100, ...)
## S3 method for class 'gqc' plot(x, fitdb = TRUE, initdb = FALSE, xlim = NULL, ylim = NULL, bg, pch, npoints = 100, ...)
x |
object of class |
fitdb |
logical. If |
initdb |
logical. If |
xlim |
the x limits of the plot. If |
ylim |
the y limits of the plot. If |
bg |
the background color to be used for points in 2D scatter plot.
Default is |
pch |
the symbols to be used as points in 2D scatter plot. Default is |
npoints |
number of points per dimension used to plot the decision bound. Default is 100. |
... |
further arguments. |
This function produces a scatter plot of data matrix in the x
and (optionally) decision boundary (i.e., x$par
and/or x$initpar
).
The look of the plot differs depending on the dimension of the model. If the dimension is 2, scatter plot of the model matrix is plotted. If the dimension is 3, plot3d.gqc
is called to create a 3D scatter plot. In all other cases, an error message will be returned.
data(subjdemo_2d) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dq)
data(subjdemo_2d) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) plot(fit.2dq)
plot the fitted 3D data set and linear decision boundary.
## S3 method for class 'glc' plot3d(x, fitdb = TRUE, initdb = FALSE, lims = NULL, alpha = .5, ...)
## S3 method for class 'glc' plot3d(x, fitdb = TRUE, initdb = FALSE, lims = NULL, alpha = .5, ...)
x |
object of class |
fitdb |
logical. If |
initdb |
logical. If |
lims |
column matrix of the x, y, and z limits of the plot |
alpha |
alpha value for the decision bound surface(s) ranging from 0 (fully transparent) to 1 (opaque). Default is .5. |
... |
further arguments. |
This function produces a 3D scatter plot of data matrix in the x
and (optionally) decision boundary specified within (i.e., x$par
and/or x$initpar
), using points3d
and quads3d
in the rgl
package respectively.
Daniel Adler, Oleg Nenadic and Walter Zucchini (2003) RGL: A R-library for 3D visualization with OpenGL
## Not run: data(subjdemo_3d) fit.3dl <- glc(response ~ x + y + z, data=subjdemo_3d, category=subjdemo_3d$category, zlimit=7) plot3d(fit.3dl) ## End(Not run)
## Not run: data(subjdemo_3d) fit.3dl <- glc(response ~ x + y + z, data=subjdemo_3d, category=subjdemo_3d$category, zlimit=7) plot3d(fit.3dl) ## End(Not run)
plot the fitted 3D data set and quadratic decision boundaries.
## S3 method for class 'gqc' plot3d(x, fitdb = TRUE, initdb = FALSE, lims = NULL, npoints = 100, alpha = .5, fill = TRUE, smooth = FALSE, ...)
## S3 method for class 'gqc' plot3d(x, fitdb = TRUE, initdb = FALSE, lims = NULL, npoints = 100, alpha = .5, fill = TRUE, smooth = FALSE, ...)
x |
object of class |
fitdb |
logical. If |
initdb |
logical. If |
lims |
column matrix of the x, y, and z limits of the plot. If |
npoints |
number of points per dimension (i.e., x, y, and z) used to plot the decision bound surface. Default is 100. |
alpha |
alpha value for the decision bound surface(s) ranging from 0 (fully transparent) to 1 (opaque). Default is .5 |
fill |
logical. If |
smooth |
logical. If |
... |
further arguments. |
This function produces a 3D scatter plot of data matrix of x
and (optionally) quadratic decision boundaries specified within (i.e., x$par
and/or x$initpar
), using points3d
function in the rgl
package and contour3d
function in the misc3d
package respectively.
Daniel Adler, Oleg Nenadic and Walter Zucchini (2003) RGL: A R-library for 3D visualization with OpenGL
## Not run: data(subjdemo_3d) fit.3dq <- gqc(response ~ x + y + z, data=subjdemo_3d, category=subjdemo_3d$category, zlimit=7) plot3d(fit.3dq) ## End(Not run)
## Not run: data(subjdemo_3d) fit.3dq <- gqc(response ~ x + y + z, data=subjdemo_3d, category=subjdemo_3d$category, zlimit=7) plot3d(fit.3dq) ## End(Not run)
Predicted classification based on ‘glc’ model object.
## S3 method for class 'glc' predict(object, newdata, seed = NULL, ...)
## S3 method for class 'glc' predict(object, newdata, seed = NULL, ...)
object |
object of class |
newdata |
a vector or a matrix containing new samples with which the classification prediction is to be made. |
seed |
numeric. The ‘seed’ used for the random number generator. |
... |
further arguments (currently unused). |
The function predict (or ‘simulate’) classification response of an observer whose noise and linear decision bounds are specified in object
.
The predicted category labels are matched with those used for the fit in object
.
If newdata
is missing, the predictions are made on the data used for the fit.
a vector of labels of categories to which each sample in newdata
is predicted to belong, according to the model in object
.
Author of the original Matlab routines: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(900, 900)) newd <- grtrnorm(n=20, np=2, means=m, covs=covs, seed=1234) predict(fit.2dl, newd[,2:3], seed=1234)
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) m <- list(c(187, 142), c(213.4, 97.7)) covs <- diag(c(900, 900)) newd <- grtrnorm(n=20, np=2, means=m, covs=covs, seed=1234) predict(fit.2dl, newd[,2:3], seed=1234)
Find coefficients of the ideal quadratic decision boundary given the means and covariance of two categories.
qdb(means, covs, pnoise = 10, cnoise = 100, sphere = FALSE)
qdb(means, covs, pnoise = 10, cnoise = 100, sphere = FALSE)
means |
a list of vectors containing means of the two distributions. |
covs |
a list containing the covariance matrices of the two distributions. |
pnoise , cnoise
|
numeric. Defaults set to 10, and 100, respectively. see ‘Details’ |
sphere |
logical. If TRUE, the returned decison bound forms a circle or sphere. |
The order of vectors in the list means
and covs
matters as the sign of coeffs
and bias
object in the output will be reversed.
The argument pnoise
and cnoise
is only for convenience; the supplied value is simply bypassed to the output for the subsequent use, i.e., as object of class gqcStruct
.
object of class gqcStruct
Author of the original Matlab routine ‘quaddecisbnd’: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
m <- list(c(187, 142), c(213.4, 97.7)) covs <- list(diag(c(625, 625)), diag(c(625, 625))) foo <- qdb(means=m, covs=covs)
m <- list(c(187, 142), c(213.4, 97.7)) covs <- list(diag(c(625, 625)), diag(c(625, 625))) foo <- qdb(means=m, covs=covs)
Calculate the proportion correct obtained by categorizing samples form one multivariate normal population using the quadratic decision boundary.
qdb.p.correct(x, qdb, refpts = colMeans(x))
qdb.p.correct(x, qdb, refpts = colMeans(x))
x |
a vector or matrix containing the values of samples from one multivariate normal population. |
qdb |
object of class |
refpts |
a numeric vector used as a reference point to determine the correct side of the |
The function assumes that all the points specified in x
belong to just one category.
Author of the original Matlab routine ‘quadbndpercorr’: Leola Alfonso-Reese
Author of R adaptation: Kazunaga Matsuki
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
data(subjdemo_2d) tmp <- split(subjdemo_2d, subjdemo_2d$category) mc <- mcovs(category ~ x + y, data=subjdemo_2d, pooled=FALSE) db <- qdb(mc$means, mc$covs) qdb.p.correct(tmp[[1]][,2:3], db)
data(subjdemo_2d) tmp <- split(subjdemo_2d, subjdemo_2d$category) mc <- mcovs(category ~ x + y, data=subjdemo_2d, pooled=FALSE) db <- qdb(mc$means, mc$covs) qdb.p.correct(tmp[[1]][,2:3], db)
Return the discriminant scores obtained by applying the general linear classifier to the fitted data.
## S3 method for class 'glc' scale(x, initdb = FALSE, zlimit = Inf, ...) ## S3 method for class 'gqc' scale(x, initdb = FALSE, zlimit = Inf, ...)
## S3 method for class 'glc' scale(x, initdb = FALSE, zlimit = Inf, ...) ## S3 method for class 'gqc' scale(x, initdb = FALSE, zlimit = Inf, ...)
x |
object of class |
initdb |
optional logical. If |
zlimit |
optional numeric. Used to truncate the scores beyond the speficied value. Default to |
... |
further arguments (currently unused) |
The generic function scale
is redefined to accept arguments other than x
, center
, and scale
.
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) scale(fit.2dl) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) scale(fit.2dq) ## Not run: #plots using the discriminant scores require(Hmisc) options(digits=3) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) # z-scores based on the initial decision bound # split by the true category membership zinit <- split(scale(fit.2dl, initdb=TRUE), subjdemo_2d$category) histbackback(zinit) # z-scores based on the fitted decision bound # split by the participants' response zfit1 <- split(scale(fit.2dl, initdb=FALSE), subjdemo_2d$category) histbackback(zfit1) # z-scores based on the fitted decision bound # split by the true category membership zfit2 <- split(scale(fit.2dl, initdb=FALSE), subjdemo_2d$response) histbackback(zfit2) ## End(Not run)
data(subjdemo_2d) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) scale(fit.2dl) fit.2dq <- gqc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) scale(fit.2dq) ## Not run: #plots using the discriminant scores require(Hmisc) options(digits=3) fit.2dl <- glc(response ~ x + y, data=subjdemo_2d, category=subjdemo_2d$category, zlimit=7) # z-scores based on the initial decision bound # split by the true category membership zinit <- split(scale(fit.2dl, initdb=TRUE), subjdemo_2d$category) histbackback(zinit) # z-scores based on the fitted decision bound # split by the participants' response zfit1 <- split(scale(fit.2dl, initdb=FALSE), subjdemo_2d$category) histbackback(zfit1) # z-scores based on the fitted decision bound # split by the true category membership zfit2 <- split(scale(fit.2dl, initdb=FALSE), subjdemo_2d$response) histbackback(zfit2) ## End(Not run)
A sample one dimensional stimulus set and response data of a hypothetical participant in a two-category classification experiment involving 500 trials.
subjdemo_1d
subjdemo_1d
This data frame contains 500 rows and the following columns:
category
label of the category to which each stimulus belongs.
x
value on the dimension 'x'
response
classification response of a participant.
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
A sample two dimensional stimulus set and response data of a hypothetical participant in a two-category classification experiment involving 500 trials.
subjdemo_2d
subjdemo_2d
This data frame contains 500 rows and the following columns:
category
label of the category to which each stimulus belongs.
x
value on the dimension 'x'
y
value on the dimension 'y'
response
classification response of a participant.
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
A sample one dimensional stimulus set and response data of a hypothetical participant in a two-category classification experiment involving 500 trials.
subjdemo_3d
subjdemo_3d
This data frame contains 500 rows and the following columns:
category
label of the category to which each stimulus belongs.
x
value on the dimension 'x'
y
value on the dimension 'y'
z
value on the dimension 'z'
response
classification response of a participant.
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
Alfonso-Reese, L. A. (2006) General recognition theory of categorization: A MATLAB toolbox. Behavior Research Methods, 38, 579-583.
A sample two dimensional stimulus set and response data of a hypothetical participant in a two-category classification experiment involving 100 trials.
subjdemo_cj
subjdemo_cj
This data frame contains 100 rows and the following columns:
category
label of the category to which each stimulus belongs.
x1
value on the dimension 'x1'
x2
value on the dimension 'x2'
response
classification response of a participant.
##### the data was generated using following codes: m <- list(c(100,200),c(100,100),c(200,100),c(200,200)) covs <- diag(30^2, ncol=2, nrow=2) set.seed(1) subjdemo_cj <- grtrnorm(n=c(50,20,10,20), np=4, means=m, covs=covs) subjdemo_cj$category <- c(1,2,2,2)[subjdemo_cj$category] ##### create ramdom responses with 80% accuracy subjdemo_cj$response <- subjdemo_cj$category set.seed(1) incorrect <- sample(1:100, size=20) subjdemo_cj$response[incorrect] <- abs(subjdemo_cj$response[incorrect] - 3) ##### plotting the dataset with(subjdemo_cj, plot(x2 ~ x1, bg=category, pch=response)) abline(h=150, lty=2) abline(v=150, lty=2)
##### the data was generated using following codes: m <- list(c(100,200),c(100,100),c(200,100),c(200,200)) covs <- diag(30^2, ncol=2, nrow=2) set.seed(1) subjdemo_cj <- grtrnorm(n=c(50,20,10,20), np=4, means=m, covs=covs) subjdemo_cj$category <- c(1,2,2,2)[subjdemo_cj$category] ##### create ramdom responses with 80% accuracy subjdemo_cj$response <- subjdemo_cj$category set.seed(1) incorrect <- sample(1:100, size=20) subjdemo_cj$response[incorrect] <- abs(subjdemo_cj$response[incorrect] - 3) ##### plotting the dataset with(subjdemo_cj, plot(x2 ~ x1, bg=category, pch=response)) abline(h=150, lty=2) abline(v=150, lty=2)
This function revert a Matrix-like object that is scaled or centered via scale.default
to data with the original scale/center.
unscale(x)
unscale(x)
x |
numeric matrix(like object). |
a matrix that are re-centered or un-scaled, based on the value of attributes "scaled:center" and "scaled:scale" of x
. If neither of those attributes is specified, x
is returned.
require(stats) x <- matrix(1:10, ncol=2) unscale(z <- scale(x)) #maybe useful for truncating trunc <- 1 z[abs(z) > trunc] <- sign(z[abs(z) > trunc])*trunc unscale(z)
require(stats) x <- matrix(1:10, ncol=2) unscale(z <- scale(x)) #maybe useful for truncating trunc <- 1 z[abs(z) > trunc] <- sign(z[abs(z) > trunc])*trunc unscale(z)