📄 ocn_g03.h
字号:
0.013 1.950
RSS = 0.019
Return:
The function returns NAG error code or 0 if no error.
70: On entry, parameter stand had an illegal value. On entry, parameter pscale had an illegal value.
11: On entry, n must not be less than 1: n = _value_. On entry, m must not be less than 1: m = _value_.
17: On entry, tdx = _value_ while m = _value_. These parameters must satisfy tdx = m. On entry, tdy = _value_ while m = _value_. These parameters must satisfy tdy = m. On entry, tdr = _value_ while m = _value_. These parameters must satisfy tdr = m.
19: On entry, m = _value_ while n = _value_. These parameters must satisfy m = n.
427: The singular value decomposition has failed to converge. This is an unlikely error exit.
512: On entry, either x or y contains only zero-points (possibly after translation) when normalization is to be applied.
513: The fitted matrix Y-hat, contains only zero-points when least-squares scaling is applied.
73: Memory allocation failed.
74: An internal error has occurred in this function. Check the function call and array sizes. If the function call is correct, please consult NAG for assistance.
successfully call of the nag_mv_orthomax function.
*/
int nag_mv_procustes(
Nag_TransNorm stand,
Nag_RotationScale pscale,
int n, // the number of points.
int m, // the number of dimensions.
double x[], // the matrix to be rotated.
int tdx, // the last dimension of the array x.
double y[], // the target matrix.
int tdy, // the last dimension of the arrays y.
double yhat[], // the fitted matrix
double r[], // the matrix of rotations.
int tdr, // the last dimension of the array r.
double *alpha, // if pscale = Nag LsqScale the scaling factor, a; otherwise alpha is not set
double *rss, // the residual sum of squares.
double res[] // the residuals.
); // Rotation matrix, Target matrix, Fitted matrix, RSS, Scale factor.
/** g03cac
computes the maximum likelihood estimates of the parameters of a factor analysis
model. Either the data matrix or a correlation/covariance matrix may be input.
Factor loadings, communalities and residual correlations are returned.
Example:
The example is taken from Lawley and Maxwell (1971). The correlation matrix for nine variables
is input and the parameters of a factor analysis model with three factors are estimated and printed.
// Note: This function needs the support of struct. It has not been done yet!
void test_nag_mv_factor()
{
matrix fl, x;
fl.SetSize(9,9);
x.SetSize(9,9);
double com[9], e[9];
double psi[9], res[36], stat[4], wt[9];
double *wtptr=NULL;
double eps;
int nfac, nvar;
int i, j, l, m, n;
int isx[9];
int tdfl = 9, tdx = 9;
char weight, char_mat;
Nag_FacMat mat;
Nag_E04_Opt options;
Vprintf("g03cac Example Program Results\n\n");
Vscanf("%*[^\n]");
Vscanf("%s",char_mat);
Vscanf("%s",weight);
Vscanf("%ld",&n);
Vscanf("%ld",&m);
Vscanf("%ld",&nvar);
Vscanf("%ld",&nfac);
if (m <= MMAX && (*char_mat == 'C' || n <= NMAX ))
{
if (*char_mat == 'C')
{
for (i = 0; i < m; ++i)
{
for (j = 0; j < m; ++j)
Vscanf("%lf",&x[i][j]);
}
}
else
{
if (*weight == 'W' || *weight == 'w')
{
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
Vscanf("%lf",&x[i][j]);
Vscanf("%lf",&wt[i]);
}
wtptr = wt;
}
else
{
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
Vscanf("%lf",&x[i][j]);
}
}
}
for (j = 0; j < m; ++j)
Vscanf("%ld",&isx[j]);
3.g03cac.6 [NP3275/5/pdf]
g03 - Multivariate Methods g03cac
if (*char_mat == 'D')
{
mat = Nag_DataCorr;
}
else if (*char_mat == 'S')
{
mat = Nag_DataCovar;
}
else if (*char_mat == 'C')
{
mat = Nag_MatCorr_Covar;
}
e04xxc(&options);
options.max_iter = 500;
options.optim_tol = 1e-2;
eps = 1e-5;
g03cac(mat, n, m, (double *)x, tdx, nvar, isx, nfac, wtptr, e,
stat, com, psi, res, (double *)fl, tdfl, &options, eps, NAGERR_DEFAULT);
Vprintf("\nEigenvalues\n\n");
for (j = 0; j < m; ++j)
{
Vprintf(" %12.4e%s",e[j], (j+1)%6==0 ? "\n" : "");
}
Vprintf("\n\n%s%6.3f\n"," Test Statistic = ",stat[1]);
Vprintf("%s%6.3f\n"," df = ",stat[2]);
Vprintf("%s%6.3f\n\n","Significance level = ",stat[3]);
Vprintf("Residuals\n\n");
l = 1;
for (i = 1; i <= nvar-1; ++i)
{
for (j = l; j <= l+i-1; ++j)
Vprintf(" %8.3f",res[j-1]);
Vprintf("\n");
l += i;
}
Vprintf("\nLoadings, Communalities and PSI\n\n");
for (i = 0; i < nvar; ++i)
{
for (j = 0; j < nfac; ++j)
Vprintf(" %8.3f",fl[i][j]);
Vprintf("%8.3f%8.3f\n", com[i], psi[i]);
}
exit(EXIT_SUCCESS);
}
else
{
Vprintf("Incorrect input value of n or m.\n");
exit(EXIT_FAILURE);
}
}
The output is following:
Parameters to e04lbc
--------------------
Number of variables........... 9
optim_tol............... 1.00e-02 linesearch_tol.......... 9.00e-01
step_max................ 2.70e+01 max_iter................ 500
print_level.........Nag_Soln_Iter machine precision....... 1.11e-16
deriv_check............. FALSE
outfile................. stdout
Memory allocation:
state................... User
hesl.................... User hesd................... User
Iterations performed = 0, function evaluations = 1
Criterion = 8.635756e-02
Variable Standardized
Communalities
1 0.5755
2 0.5863
3 0.4344
4 0.7496
5 0.6203
6 0.7329
7 0.6061
8 0.4053
9 0.7104
Iterations performed = 1, function evaluations = 3
Criterion = 3.603203e-02
Variable Standardized
Communalities
1 0.5517
2 0.5800
3 0.3936
4 0.7926
5 0.6140
6 0.8254
7 0.6052
8 0.5076
9 0.7569
Iterations performed = 2, function evaluations = 4
Criterion = 3.502097e-02
Variable Standardized
Communalities
1 0.5496
2 0.5731
3 0.3838
4 0.7875
5 0.6200
6 0.8238
7 0.6006
8 0.5349
9 0.7697
Iterations performed = 3, function evaluations = 5
Criterion = 3.501729e-02
Variable Standardized
Communalities
1 0.5495
2 0.5729
3 0.3835
4 0.7877
5 0.6195
6 0.8231
7 0.6005
8 0.5384
9 0.7691
Eigenvalues
1.5968e+01 4.3577e+00 1.8474e+00 1.1560e+00 1.1190e+00 1.0271e+00
9.2574e-01 8.9508e-01 8.7710e-01
Test Statistic = 7.149
df = 12.000
Significance level = 0.848
Residuals
0.000
-0.013 0.022
0.011 -0.005 0.023
-0.010 -0.019 -0.016 0.003
-0.005 0.011 -0.012 -0.001 -0.001
0.015 -0.022 -0.011 0.002 0.029 -0.012
-0.001 -0.011 0.013 0.005 -0.006 -0.001 0.003
-0.006 0.010 -0.005 -0.011 0.002 0.007 0.003 -0.001
Loadings, Communalities and PSI
0.664 -0.321 0.074 0.550 0.450
0.689 -0.247 -0.193 0.573 0.427
0.493 -0.302 -0.222 0.383 0.617
0.837 0.292 -0.035 0.788 0.212
0.705 0.315 -0.153 0.619 0.381
0.819 0.377 0.105 0.823 0.177
0.661 -0.396 -0.078 0.600 0.400
0.458 -0.296 0.491 0.538 0.462
0.766 -0.427 -0.012 0.769 0.231
Return:
The function returns NAG error code or 0 if no error.
70: On entry, parameter matrix had an illegal value.
11: On entry, nfac must not be less than 1: nfac = _value_. On entry, nvar must not be less than 2: nvar = _value_.
17: On entry, m = _value_ while nvar = _value_. These parameters must satisfy m = nvar. On entry, tdx = _value_ while m = _value_. These parameters must satisfy tdx = m. On entry, td. = _value_ while nfac = _value_. These parameters must satisfy td. = nfac.
18: On entry, n = _value_ while nvar = _value_. These parameters must satisfy n > nvar.
19: On entry, nfac = _value_ while nvar = _value_. These parameters must satisfy nfac = nvar.
44: Value _value_ given to eps is not valid. Correct range is machine precision = eps < 1.0.
500: On entry, wt[_value_] = _value_. Constraint: When referenced, all elements of wt must be non-negative.
501: The number of variables, nvar in the analysis = _value_, while number of variables included in the analysis via array isx = _value_. Constraint: these two numbers must be the same.
503: With weighted data, the e.ective number of observations given by the sum of weights = _value_, while the number of variables included in the analysis, nvar = _value_. Constraint: e.ective number of observations > nvar + 1.
427: A singular value decomposition has failed to converge. This is a very unlikely error exit.
284: The conditions for a minimum have not all been satis.ed but a lower point could not be found. Note that in this case all the results are computed. See nag opt bounds 2nd deriv (e04lbc) for further details.
285:The maximum number of iterations, _value_, have been performed.
514: On entry, matrix = Nag DataCorr or matrix = Nag DataCovar and the data matrix is not of full column rank, or matrix = Nag MatCorr Covar and the input correlation/variancecovariance matrix is not positive-de.nite. This exit may also be caused by two of the eigenvalues of S* being equal; this is rare (see Lawley and Maxwell (1971)) and may be due to the data/correlation matrix being almost singular.
73: Memory allocation failed.
74: An internal error has occurred in this function. Check the function call and array sizes. If the function call is correct, please consult NAG for assistance. Additional error messages will output if the optimisation fails to converge or if the options are set incorrectly. Details of these can be found in the nag opt bounds 2nd deriv (e04lbc) document.
successfully call of the nag_mv_factor function.
*/
/**
int nag_mv_factor(
Nag_FacMat mat,
int n, // the number of observations .
int m, // the number of variables in the data/correlation/variance-covariance matrix.
double x[], // the input matrix.
int tdx, // the last dimension of the array x.
int nvar, // the number of variables in the factor analysis.
int isx[], // indicates whether or not the jth variable is to be included in the factor analysis.
int nfac, // the number of factors.
double *wtptr, // the weights to be used in the factor analysis.
double e[], // the eigenvalues.
double stat[], // the test statistics.
double com[], // the communalities.
double psi[], // the estimates of psi(i), for i = 1, 2, . . . , p.
double res[], // the residual correlations.
double fl[], // the factor loadings.
int tdfl, // the last dimension of the array fl.
Nag_E04_Opt *options,
double eps, // A lower bound for the value of 豬.
); // Loadings, Communalities and PSI, Eigenvalues, Standardized Communalities, ....
*/
/** g03ccc
computes factor score coefficients from the result of fitting a factor analysis
model by maximum likelihood as performed by nag mv factor (g03cac).
Example:
The example is taken from Lawley and Maxwell (1971). The correlation matrix
for 220 observations on six school subjects is input and a factor analysis
model with two factors .tted using nag mv factor (g03cac). The factor score
coefficients are computed using the regression method.
// Note: This one needs the support of the the results of the g03cac
Return:
The function returns NAG error code or 0 if no error.
70: On entry, parameter method had an illegal value. On entry, parameter rotate had an illegal value.
11: On entry, nfac must not be less than 1: nfac = _value_.
17: On entry, nvar = _value_ while nfac = _value_. These parameters must satisfy nvar = nfac. On entry, td. = _value_ while nfac = _value_. These parameters must satisfy td. = nfac. On entry, tdfs = _value_ while nfac = _value_. These parameters must satisfy tdfs = nfac.
109: On entry, tdr = _value_ while nfac = _value_ and rotate = Nag FacRotate. These parameters must satisfy tdr = nfac when rotate = Nag FacRotate.
55: On entry, e[_value_] = _value_. Constraint: e[_value_] > 1.0. On entry, psi[_value_] = _value_. Constraint: psi[_value_] > 0.0.
73: Memory allocation failed.
74: An internal error has occurred in this function. Check the function call and array sizes. If the function call is correct, please consult NAG for assistance.
*/
/**
int nag_mv_fac_score(
Nag_FacScoreMethod method,
Nag_FacRotation rotate,
int nvar, // the number of observed variables in the factor analysis.
int nfac, // the number of factors in the factor analysis.
double fl[], // the matrix of unrotated factor loadings,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -