Testing slope of line created with polyval for significance (slope ~= 0)

22 views (last 30 days)
Hi there,
I have generated a line from some parameters (slope and intercept) using polyval.
% Get data
coeff = [-0.5358 0.6167];
x_short = [(16/36), (16/28), (16/16), (28/16), (36/16)]; % stimulus sizes
x_long = linspace(x_short(1), x_short(end), 5000); % make long vector for stimulus sizes - to allow making a smoother curve when you fit a curve to your this in other steps later
x = log(x_long); % make spacings more even
clear x_short x_long
% Fit line
line = polyval(coeff,x);
% Plot line
plot(x,line);
I would like to test if the slope of the line is significantly different from 0. That is, is the line sloping or is it flat?
I thought I might be able to do this by fitting a linear model, which tests both parameters of the line (i.e., coeff, from above) for significance with a t-test.
% Test slope by fitting linear model
lm = fitlm(x, line);
slope_tStat = table2array(lm.Coefficients(2,3));
slope_pStat = table2array(lm.Coefficients(2,4));
slope_df = lm.DFE;
But looking at the degrees of freedom, it seems like this significance test is influenced by how long my x axis/ line is (slope_df = 4998), which is not what I want.
I *think* I want to compare a model where the line has the parameters above (-0.5358 0.6167) with a model that has no slope but same intercept (0, 0.6167), to see if the slope is significant (?) But I’m not sure this is the correct approach, and not sure how to implement this in matlab if I were to do this.
Does anyone know how I can test if the slope of this line is different to 0 - without the outcome of the test being dependent on how long my line/ x vector is?
Any insights would be incredibly helpful, I have been stuck on this for a very long time.
Thank you in advance,
Harriet

Answers (1)

Star Strider
Star Strider on 18 Jul 2022
I am not certain what you are asking.
If you are doing a linear regression, then use fitlm with the same data you used with polyfit to calculate ‘coeffs’, since fitlm will give you all the necessary statistics. The confidence intervals on the parameters (slope and intercept) will give the probabilities that they are each different from zero.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!