Curve fitting toolbox linear fit to find confidence interval that includes zero

1 view (last 30 days)
Hi, I'm trying to find out the p-value for which the slope of my linear fit is significantly different than zero. I am using the CFTOOL function with a linear polynomial fit. One of the outputs is the 95% confidence interval, but I would like to find at what confidence interval is one of the bounds equal to zero. Do you know of a way to do this?
I have tried other functions but CFTOOL seems to work best because I have multiple y values for each x. I also have NaN's in the data that CFTOOL correctly ignores, whereas the other functions do not handle the NaN's well.
Thanks! Nick
  3 Comments
the cyclist
the cyclist on 30 Aug 2013
I don't have the curve fitting toolbox, so I cannot experiment.
Can you be more specific about what the output looks like, ideally with an example?
Matt J
Matt J on 30 Aug 2013
One of the outputs is the 95% confidence interval, but I would like to find at what confidence interval is one of the bounds equal to zero.
In order to calculate that, you would have to know the true slope, wouldn't you? The more the true slope differs from zero, the larger the % confidence interval needed to include zero.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 30 Aug 2013
I think I understand what you mean now. Doesn't CFTOOL directly output that p-value?
If not, I think you can calculate the p-value as follows. I tested this a bit, and got reasonable results, but definitely check this. This assumes that CFTOOL makes normality assumptions.
% Significance of cftool output (default is probably 0.05)
ALPHA = 0.05;
% z-score of the lower bound of a unit normal
z95lower = norminv(ALPHA/2);
% Sample mean slope as calculated by cftool
meanSlope = 3; % <------- Get this value from output of cftool
% Confidence interval as calculated by cftool
lowerCI = 0.5; % <------- Get this value from output of cftool
% Inferred standard error of the mean of the slope
stdErr = (meanSlope - lowerCI)/z95lower;
% z-score of zero (the number of standard errors that zero is away from the mean slope)
z_score_at_zero = meanSlope/stdErr;
% p-value of that z-score
p_value_from_zero = 2*normcdf(z_score_at_zero)

Community Treasure Hunt

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

Start Hunting!