NAG Library Function Document nag_regsn_mult_linear_upd_model (g02ddc)

Similar documents
NAG Library Function Document nag_regsn_mult_linear_delete_var (g02dfc)

NAG Library Function Document nag_regsn_mult_linear_addrem_obs (g02dcc)

NAG Library Function Document nag_dummy_vars (g04eac)

nag regsn mult linear upd model (g02ddc)

NAG Library Function Document nag_mv_prin_comp (g03aac)

NAG Library Function Document nag_dummy_vars (g04eac)

NAG Library Function Document nag_mv_discrim (g03dac)

NAG Library Function Document nag_glm_tran_model (g02gkc)

NAG Library Function Document nag_corr_cov (g02bxc)

NAG Library Function Document nag_smooth_spline_fit (g10abc)

NAG Library Function Document nag_friedman_test (g08aec)

nag regsn mult linear add var (g02dec)

NAG Library Function Document nag_dgelsd (f08kcc)

NAG Library Function Document nag_kalman_sqrt_filt_info_var (g13ecc)

NAG Library Function Document nag_durbin_watson_stat (g02fcc)

NAG Library Function Document nag_regress_confid_interval (g02cbc)

NAG Library Function Document nag_mv_discrim (g03dac)

nag regsn mult linear delete var (g02dfc)

NAG Library Function Document nag_sum_sqs_update (g02btc)

NAG Library Function Document nag_frequency_table (g01aec)

nag regsn mult linear est func (g02dnc)

NAG Library Function Document nag_mv_dendrogram (g03ehc)

NAG Library Function Document nag_kruskal_wallis_test (g08afc)

NAG Library Function Document nag_dspr (f16pqc)

NAG Library Function Document nag_glm_predict (g02gpc)

NAG Library Function Document nag_full_step_regsn (g02efc)

NAG Library Function Document nag_robust_m_corr_user_fn (g02hlc)

NAG Library Function Document nag_dspsv (f07pac)

NAG Library Routine Document G02DDF.1

NAG Library Function Document nag_zgelss (f08knc)

NAG Library Function Document nag_robust_m_corr_user_fn_no_derr (g02hmc)

NAG Library Function Document nag_dtpsv (f16plc)

NAG Library Function Document nag_corr_cov (g02bxc)

NAG Library Function Document nag_sparse_nsym_sol (f11dec)

NAG Library Function Document nag_smooth_spline_fit (g10abc)

NAG Library Function Document nag_stable_sort (m01ctc)

NAG Library Function Document nag_summary_stats_onevar_combine (g01auc)

NAG Library Function Document nag_sparse_sym_sol (f11jec)

NAG Library Function Document nag_zhpev (f08gnc)

NAG Library Function Document nag_outlier_peirce (g07gac)

NAG Library Function Document nag_search_vector (m01fsc)

NAG Library Function Document nag_sparse_nherm_jacobi (f11dxc)

NAG Library Function Document nag_mv_ordinal_multidimscale (g03fcc)

NAG Library Function Document nag_mv_promax (g03bdc)

NAG Library Function Document nag_mv_distance_mat (g03eac)

NAG Library Function Document nag_mldwt_2d (c09ecc)

NAG Library Function Document nag_tsa_auto_corr_part (g13acc)

NAG Library Function Document nag_zgelsy (f08bnc)

NAG Library Function Document nag_prob_durbin_watson (g01epc)

NAG Library Function Document nag_prob_non_central_f_dist (g01gdc)

NAG Library Function Document nag_chi_sq_2_way_table (g11aac)

NAG Library Function Document nag_dgetrf (f07adc)

NAG Library Function Document nag_partial_corr (g02byc)

NAG Library Function Document nag_dtpttr (f01vcc)

NAG Library Function Document nag_tsa_noise_spectrum_bivar (g13cgc)

NAG Library Function Document nag_5d_shep_eval (e01tnc)

NAG Library Function Document nag_wfilt (c09aac)

NAG Library Function Document nag_2_sample_ks_test (g08cdc)

NAG Library Function Document nag_2d_spline_eval (e02dec)

NAG Library Function Document nag_legendre_p (s22aac)

NAG Library Function Document nag_anova_random (g04bbc)

NAG Library Function Document nag_zsymv (f16tac)

NAG Library Function Document nag_tsa_dickey_fuller_unit (g13awc)

NAG Library Function Document nag_dgbmv (f16pbc)

NAG Library Function Document nag_sparse_nsym_precon_ssor_solve (f11ddc)

NAG Library Function Document nag_dsygv (f08sac)

NAG Library Function Document nag_1d_spline_fit_knots (e02bac)

NAG Library Function Document nag_real_gen_matrix_exp (f01ecc)

NAG Library Function Document nag_dsbev (f08hac)

NAG Library Function Document nag_bsm_price (s30aac)

NAG Library Function Document nag_dwt (c09cac)

NAG Library Function Document nag_opt_check_deriv (e04hcc)

NAG Library Function Document nag_dstev (f08jac)

NAG Library Function Document nag_dsf_norm (f16rkc)

NAG Library Function Document nag_dtrttf (f01vec)

NAG Library Function Document nag_tsa_varma_update (g13dkc)

NAG Library Function Document nag_real_cholesky_skyline_solve (f04mcc)

NAG Library Function Document nag_dtfttp (f01vlc)

NAG Library Function Document nag_4d_shep_eval (e01tlc)

NAG C Library Function Document nag_binary_factor_service (g11sbc)

NAG Library Function Document nag_zhfrk (f16zqc)

NAG Library Function Document nag_all_regsn (g02eac)

NAG Library Function Document nag_zhpr2 (f16ssc)

NAG Library Function Document nag_1d_spline_evaluate (e02bbc)

NAG Library Function Document nag_ode_bvp_fd_nonlin_fixedbc (d02gac)

NAG Library Function Document nag_dger (f16pmc)

NAG Library Function Document nag_dgglse (f08zac)

NAG Library Function Document nag_dtrmv (f16pfc)

NAG Library Function Document nag_1d_spline_deriv (e02bcc)

NAG C Library Function Document nag_rank_regsn (g08rac)

NAG Library Function Document nag_dgges (f08xac)

NAG Library Function Document nag_ode_bvp_fd_lin_gen (d02gbc)

NAG Library Function Document nag_lars_param (g02mcc)

NAG Library Function Document nag_dgttrs (f07cec)

NAG C Library Function Document nag_anova_row_col (g04bcc)

nag glm est func (g02gnc)

NAG Library Function Document nag_quad_md_gauss (d01fbc)

NAG Library Function Document nag_dtrsyl (f08qhc)

NAG Library Function Document nag_zpbequ (f07htc)

NAG Library Function Document nag_ode_bvp_ps_lin_cheb_eval (d02uzc)

Transcription:

NAG Library Function Document nag_regsn_mult_linear_upd_model () 1 Purpose nag_regsn_mult_linear_upd_model () calculates the regression arguments for a general linear regression model. It is intended to be called after nag_regsn_mult_linear_addrem_obs (g02dcc), nag_regsn_mult_linear_add_var (g02dec) or nag_regsn_mult_linear_delete_var (g02dfc). 2 Specification #include <nag.h> #include <nagg02.h> void nag_regsn_mult_linear_upd_model (Integer n, Integer ip, const double q[], Integer tdq, double *rss, double *df, double b[], double se[], double cov[], Nag_Boolean *svd, Integer *rank, double p[], double tol, NagError *fail) 3 Description A general linear regression model fitted by nag_regsn_mult_linear (g02dac) may be adjusted by adding or deleting an observation using nag_regsn_mult_linear_addrem_obs (g02dcc), adding a new independent variable using nag_regsn_mult_linear_add_var (g02dec) or deleting an existing independent variable using nag_regsn_mult_linear_delete_var (g02dfc). These functions compute the vector c and the upper triangular matrix R. nag_regsn_mult_linear_upd_model () takes these basic results and computes the regression coefficients, ^, their standard errors and their variance-covariance matrix. If R is of full rank, then ^ is the solution to: R ^ ¼ c 1 ; where c 1 is the first p elements of c. If R is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of R, R ¼ Q D 0 P T 0 0 where D is a k by k diagonal matrix with nonzero diagonal elements, k being the rank of R, andq and P are p by p orthogonal matrices. This gives the solution ^ ¼ P 1 D 1 Q T 1 c 1 P 1 being the first k columns of P, i.e., P ¼ ðp 1 P 0 Þ and Q 1 being the first k columns of Q. Details of the SVD, are made available, in the form of the matrix P : P ¼ D 1 P1 T P0 T This will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the arguments. These solutions can be obtained by calling nag_regsn_mult_linear_tran_model (g02dkc) after calling nag_regsn_mult_linear_upd_model (). Only certain linear combinations of the arguments will have unique estimates, these are known as estimable functions. These can be estimated using nag_regsn_mult_linear_est_func (g02dnc). The residual sum of squares required to calculate the standard errors and the variance-covariance matrix can either be input or can be calculated if additional information on c for the whole sample is provided..1

NAG Library Manual 4 References Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2 25 Searle S R (1971) Linear Models Wiley 5 Arguments 1: n Integer Input On entry: number of observations. Constraint: n 1. 2: ip Integer Input On entry: the number of terms in the regression model, p. Constraint: ip 1. 3: q½n tdqš const double Input Note: theði; jþth element of the matrix Q is stored in q½ði 1Þtdq þ j 1Š. On entry: q must be the array q as output by nag_regsn_mult_linear_addrem_obs (g02dcc), nag_regsn_mult_linear_add_var (g02dec) or nag_regsn_mult_linear_delete_var (g02dfc). If on entry rss 0:0 then all n elements of c are needed. This is provided by functions nag_regsn_mult_linear_add_var (g02dec) or nag_regsn_mult_linear_delete_var (g02dfc). 4: tdq Integer Input On entry: the stride separating matrix column elements in the array q. Constraint: tdq ip þ 1. 5: rss double * Input/Output On entry: either the residual sum of squares or a value less than or equal to 0.0 to indicate that the residual sum of squares is to be calculated by the function. On exit: if rss 0:0 on entry, then on exit rss will contain the residual sum of squares as calculated by nag_regsn_mult_linear_upd_model (). If rss was positive on entry, then it will be unchanged. 6: df double * Output On exit: the degrees of freedom associated with the residual sum of squares. 7: b½ipš double Output On exit: the estimates of the p arguments, ^. 8: se½ipš double Output On exit: the standard errors of the p arguments given in b. 9: cov½ip ðip þ 1Þ=2Š double Output On exit: the upper triangular part of the variance-covariance matrix of the p parameter estimates given in b. They are stored packed by column, i.e., the covariance between the parameter estimate.2

given in b½iš and the parameter estimate given in b½jš, j i, isstoredincov½jðjþ 1Þ=2 þ iš, for i ¼ 0; 1;...; ip 1andj¼i;...; ip 1. 10: svd Nag_Boolean * Output On exit: if a singular value decomposition has been performed, then svd ¼ Nag TRUE, otherwise svd ¼ Nag FALSE. 11: rank Integer* Output On exit: the rank of the independent variables. If svd ¼ Nag FALSE, rank ¼ ip. If svd ¼ Nag TRUE, rank is an estimate of the rank of the independent variables. rank is calculated as the number of singular values greater than tol (largest singular value). It is possible for the singular value decomposition to be carried out but rank to be returned as ip. 12: p½ip ip þ 2 ipš double Output On exit: p contains details of the singular value decomposition if used. If svd ¼ Nag FALSE, p is not referenced. If svd ¼ Nag TRUE, the first ip elements of p will not be referenced, the next ip values contain the singular values. The following ip ip values contain the matrix P stored by rows. 13: tol double Input On entry: the value of tol is used to decide if the independent variables are of full rank and, if not, what is the rank of the independent variables. The smaller the value of tol the stricter the criterion for selecting the singular value decomposition. If tol ¼ 0:0, then the singular value decomposition will never be used, this may cause run time errors or inaccuracies if the independent variables are not of full rank. Suggested value: tol ¼ 0:000001. Constraint: tol 0:0. 14: fail NagError* Input/Output The NAG error argument (see Section 3.6 in the Essential Introduction). 6 Error Indicators and Warnings NE_2_INT_ARG_LT On entry, n ¼ hvaluei while ip ¼ hvaluei. These arguments must satisfy n ip. On entry, tdq ¼ hvaluei while ip þ 1 ¼ hvaluei. These arguments must satisfy tdq ip þ 1. NE_ALLOC_FAIL Dynamic memory allocation failed. NE_DOF_LE_ZERO The degrees of freedom for error are less than or equal to 0. In this case the estimates, ^, are returned but not the standard errors or covariances. NE_INT_ARG_LT On entry, ip ¼ hvaluei. Constraint: ip 1..3

NAG Library Manual On entry, n ¼ hvaluei. Constraint: n 1. NE_REAL_ARG_LT On entry, tol must not be less than 0.0: tol ¼ hvaluei. NE_SVD_NOT_CONV The singular value decomposition has failed to converge. This is an unlikely error exit. 7 Accuracy The accuracy of the results will depend on the accuracy of the input R matrix, which may lose accuracy if a large number of observations or variables have been dropped. 8 Parallelism and Performance Not applicable. 9 Further Comments None. 10 Example A dataset consisting of 12 observations and four independent variables is input and a regression model fitted by calls to nag_regsn_mult_linear_add_var (g02dec). The arguments are then calculated by nag_regsn_mult_linear_upd_model () and the results printed. 10.1 Program Text /* nag_regsn_mult_linear_upd_model () Example Program. * * Copyright 2014 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. #include <nag.h> #include <stdio.h> #include <nag_stdlib.h> #include <nagg02.h> #define X(I, J) x[(i) *tdx + J] #define Q(I, J) q[(i) *tdq + J] int main(void) Integer exit_status = 0, i, ip, ipmax, j, m, n, rank, tdq, tdx; double *b = 0, *cov = 0, df, *p = 0, *q = 0, rss, *se = 0, tol, *wt = 0; double *wtptr, *x = 0, *xe = 0; char nag_enum_arg[40]; Nag_Boolean svd, weight; NagError fail; INIT_FAIL(fail); printf( "nag_regsn_mult_linear_upd_model () Example Program Results\n"); /* Skip heading in data file scanf_s("%*[^\n]");.4

scanf("%*[^\n]"); scanf_s("%"nag_ifmt" %"NAG_IFMT" %39s", &n, &m, nag_enum_arg, _countof(nag_enum_arg)); scanf("%"nag_ifmt" %"NAG_IFMT" %39s", &n, &m, nag_enum_arg); /* nag_enum_name_to_value (x04nac). * Converts NAG enum member name to value weight = (Nag_Boolean) nag_enum_name_to_value(nag_enum_arg); ipmax = 4; if (n >= 1 && m >= 1) if (!(b = NAG_ALLOC(ipmax, double))!(cov = NAG_ALLOC(ipmax*(ipmax+1)/2, double))!(p = NAG_ALLOC(ipmax*(ipmax+2), double))!(wt = NAG_ALLOC(n, double))!(x = NAG_ALLOC(n*m, double))!(xe = NAG_ALLOC(n, double))!(se = NAG_ALLOC(ipmax, double))!(q = NAG_ALLOC(n*(ipmax+1), double))) printf("allocation failure\n"); exit_status = -1; goto END; tdx = m; tdq = ipmax+1; printf("invalid n or m.\n"); exit_status = 1; return exit_status; if (weight) wtptr = wt; wtptr = (double *) 0; if (wtptr) for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf_s("%lf", &X(i, j)); scanf("%lf", &X(i, j)); #ifdef _WIN32 scanf_s("%lf%lf", &Q(i, 0), &wt[i]); scanf("%lf%lf", &Q(i, 0), &wt[i]); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf_s("%lf", &X(i, j)); scanf("%lf", &X(i, j)); scanf_s("%lf", &Q(i, 0));.5

NAG Library Manual scanf("%lf", &Q(i, 0)); /* Set tolerance tol = 0.000001e0; ip = 0; for (j = 0; j < m; ++j) /* * Fit model using g02dec for (i = 0; i < n; i++) xe[i] = X(i, j); /* nag_regsn_mult_linear_add_var (g02dec). * Add a new independent variable to a general linear * regression model nag_regsn_mult_linear_add_var(n, ip, q, tdq, p, wtptr, xe, &rss, tol, &fail); if (fail.code == NE_NOERROR) ip += 1; if (fail.code == NE_NVAR_NOT_IND) printf(" * New variable not added * \n"); printf( "Error from nag_regsn_mult_linear_add_var (g02dec).\n%s\n", fail.message); exit_status = 1; goto END; rss = 0.0; /* nag_regsn_mult_linear_upd_model (). * Estimates of regression parameters from an updated model nag_regsn_mult_linear_upd_model(n, ip, q, tdq, &rss, &df, b, se, cov, &svd, &rank, p, tol, &fail); if (fail.code!= NE_NOERROR) printf( "Error from nag_regsn_mult_linear_upd_model ().\n%s\n", fail.message); exit_status = 1; goto END; printf("\n"); if (svd) printf("model not of full rank\n\n"); printf("residual sum of squares = %13.4e\n", rss); printf("degrees of freedom = %3.1f\n\n", df); printf("variable Parameter estimate Standard error\n\n"); for (j = 0; j < ip; j++) printf("%6"nag_ifmt"%20.4e%20.4e\n", j+1, b[j], se[j]); printf("\n"); END: NAG_FREE(b); NAG_FREE(cov); NAG_FREE(p); NAG_FREE(wt); NAG_FREE(x); NAG_FREE(xe);.6

NAG_FREE(se); NAG_FREE(q); return exit_status; 10.2 Program Data nag_regsn_mult_linear_upd_model () Example Program Data 12 4 Nag_FALSE 1.0 0.0 0.0 0.0 33.63 0.0 0.0 0.0 1.0 39.62 0.0 1.0 0.0 0.0 38.18 0.0 0.0 1.0 0.0 41.46 0.0 0.0 0.0 1.0 38.02 0.0 1.0 0.0 0.0 35.83 0.0 0.0 0.0 1.0 35.99 1.0 0.0 0.0 0.0 36.58 0.0 0.0 1.0 0.0 42.92 1.0 0.0 0.0 0.0 37.80 0.0 0.0 1.0 0.0 40.43 0.0 1.0 0.0 0.0 37.89 10.3 Program Results nag_regsn_mult_linear_upd_model () Example Program Results Residual sum of squares = 2.2227e+01 Degrees of freedom = 8.0 Variable Parameter estimate Standard error 1 3.6003e+01 9.6235e-01 2 3.7300e+01 9.6235e-01 3 4.1603e+01 9.6235e-01 4 3.7877e+01 9.6235e-01.7 (last)