MATLAB: How to compute a partial F-test for multiple linear regression

f-testmultiplelinearregressionpartialStatistics and Machine Learning Toolbox

How can I compute a partial F-test for multiple linear regression in MATLAB?
I see built-in functions to compute an F-test, but not to compute a partial F-test.

Best Answer

You can use the function "coefTest" to find both the overall F-test and a partial F-test. Here's an example of the general process:
>> % Setting up the data and example
>> load hald
>> f = fitlm(ingredients,heat)
This returns a table with the overall p-values and t-statistics for individual coefficients and overall statistics for the intercept. However, you can also use "coefTest" to compute other partial F statistics by declaring a matrix M so that M*b (b is the vector of coefficient estimates) specifies the constraints that you want to set to zero. Here is examples using this method to compute the overall F statistic, a single t statistic, and a partial F statistic for testing two coefficients.
Notice the overall F and p values from above - here is how they are computed:
>> M = [0 1 0 0 0; 0 0 1 0 0; 0 0 0 1 0; 0 0 0 0 1];
>> [p,F] = coefTest(f,M)
Notice the t and p values for x1 - here is how they are computed:
>> M = [0 1 0 0 0];
>> [p,F] = coefTest(f,M)
>> sqrt(F)
To compute a partial F-test for just coefficients x3 and x4:
>> M = [0 0 0 1 0; 0 0 0 0 1];
>> [p,F] = coefTest(f,M)
Alternatively, you could use the function "stepwiselm" to perform the partial F-test. See the following documentation page for more information about "stepwiselm":
"stepwiselm" starts with a model, and incrementally adds or removes features to find the best model according to the specified criterion. One of the criteria is SSE (sum of squared errors). You can see the F-statistic for each model during the adding/removing of the features while the training is done.