While running the below code I am getting an error saying: ERROR: (execution) Matrix has not been set to a value.
Please find below the code and the log.
proc iml;
/* If x is univariate, you can construct a matrix where
each column contains a jackknife sample.
Use for univariate column vector x when n < 20000 */
start JackSampMat(x);
n = nrow(x);
B = j(n-1, n,0);
do i = 1 to n;
B[,i] = remove(x, i)`; /* transpose to column vevtor */
end;
return B;
finish;
/* Input: matrix where each column of X is a bootstrap sample.
Return a row vector of statistics, one for each column. */
start EvalStatMat(x);
return std(x); /* <== Example: return std dev of each sample */
finish;
x = {58,67,74,74,80,89,95,97,98,107}; /* Weight gain (g) for 10 rats */
/* optional: visualize the matrix of jackknife samples */
*M = JackSampMat(x);
*print M[c=("S1":"S10") r=("1":"9")];
/* Jackknife method for univariate data */
/* 1. compute observed statistic */
T = EvalStatMat(x);
/* 2. compute same statistic on each jackknife sample */
T_LOO = EvalStatMat( JackSampMat(x) ); /* LOO = "Leave One Out" */
/* 3. compute mean of the LOO statistics */
T_Avg = mean( T_LOO` ); /* transpose T_LOO */
/* 4 & 5. compute jackknife estimates of bias and standard error */
biasJack = (n-1)*(T_Avg - T);
stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );
result = T || T_Avg || biasJack || stdErrJack;
print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];
Log says:
N is only defined locally, that is within the JackSampMat module. To reference it outside the module you will need to define it globally by adding the GLOBAL clause to the module definition.
proc iml;
/* If x is univariate, you can construct a matrix where
each column contains a jackknife sample.
Use for univariate column vector x when n < 20000 */
start JackSampMat(x) global(n);
n = nrow(x);
B = j(n-1, n,0);
do i = 1 to n;
B[,i] = remove(x, i)`; /* transpose to column vevtor */
end;
return B;
finish;
/* Input: matrix where each column of X is a bootstrap sample.
Return a row vector of statistics, one for each column. */
start EvalStatMat(x);
return std(x); /* <== Example: return std dev of each sample */
finish;
x = {58,67,74,74,80,89,95,97,98,107}; /* Weight gain (g) for 10 rats */
/* optional: visualize the matrix of jackknife samples */
*M = JackSampMat(x);
*print M[c=("S1":"S10") r=("1":"9")];
/* Jackknife method for univariate data */
/* 1. compute observed statistic */
T = EvalStatMat(x);
/* 2. compute same statistic on each jackknife sample */
T_LOO = EvalStatMat( JackSampMat(x) ); /* LOO = "Leave One Out" */
/* 3. compute mean of the LOO statistics */
T_Avg = mean( T_LOO` ); /* transpose T_LOO */
/* 4 & 5. compute jackknife estimates of bias and standard error */
biasJack = (n-1)*(T_Avg - T);
stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );
result = T || T_Avg || biasJack || stdErrJack;
print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];
N is only defined locally, that is within the JackSampMat module. To reference it outside the module you will need to define it globally by adding the GLOBAL clause to the module definition.
proc iml;
/* If x is univariate, you can construct a matrix where
each column contains a jackknife sample.
Use for univariate column vector x when n < 20000 */
start JackSampMat(x) global(n);
n = nrow(x);
B = j(n-1, n,0);
do i = 1 to n;
B[,i] = remove(x, i)`; /* transpose to column vevtor */
end;
return B;
finish;
/* Input: matrix where each column of X is a bootstrap sample.
Return a row vector of statistics, one for each column. */
start EvalStatMat(x);
return std(x); /* <== Example: return std dev of each sample */
finish;
x = {58,67,74,74,80,89,95,97,98,107}; /* Weight gain (g) for 10 rats */
/* optional: visualize the matrix of jackknife samples */
*M = JackSampMat(x);
*print M[c=("S1":"S10") r=("1":"9")];
/* Jackknife method for univariate data */
/* 1. compute observed statistic */
T = EvalStatMat(x);
/* 2. compute same statistic on each jackknife sample */
T_LOO = EvalStatMat( JackSampMat(x) ); /* LOO = "Leave One Out" */
/* 3. compute mean of the LOO statistics */
T_Avg = mean( T_LOO` ); /* transpose T_LOO */
/* 4 & 5. compute jackknife estimates of bias and standard error */
biasJack = (n-1)*(T_Avg - T);
stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );
result = T || T_Avg || biasJack || stdErrJack;
print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];
106 biasJack = (n-1)*(T_Avg - T); ERROR: (execution) Matrix has not been set to a value. operation : - at line 106 column 14 operands : n, *LIT1005 n 0 row 0 col (type ?, size 0)
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.