Calculating slope of a curve at a single point (where x = 0.5) and testing that slope for significance (slope ~= 0)
4 views (last 30 days)
I have been fitting a logistic regression model to some data using glmfit:
dataStims = [(16/36), (16/28), (16/16), (28/16), (36/16)]; % stimulus sizes
dataStims_long = linspace(dataStims(1), dataStims(end), 5000); % make long vector for stimulus sizes - to allow you to make a smoother curve when you fit a curve to your data
dataStims = log(dataStims); % take log to make spacing more even
dataStims_long = log(dataStims_long); % ''
dataResp = [9, 8, 6, 6, 0]; % count of affirmative responses (question: 'stimulus was down?' (options: down/ across)
dataCount = [10, 10, 10, 10, 10]; % count of trials presented
[~, ~, stats] = glmfit(dataStims', [dataResp' dataCount'], 'binomial', 'logit'); % fit logistic reg
This allows me to get some coefficients for the fit (stats.beta), which are
Which I understand to be the y-intercept and slope, respectively (someone please correct me if I am wrong). I also believe that the slope value returned is the slope of the line at the y-intercept (y = 0), is this correct too?
I am a bit confused re. the y-intercept, because it looks from the plot like the y-intercept ~= .6 (see image below). That is, the x value when y = 0 is ~= .6. But the y-intercept according to the stats.beta = 0.4667. Could someone let me know if I have misunderstood this?
FYI, I generated the curve using the following
logitFit_long = glmval(logitCoef, dataStims_long', 'logit');
To my main question: what I would like to do, is get the slope not at the y-intercept, but at the point of the line where x = .5 (marked by a * on the plot below). I want to get the slope at that point, and then test the significance of the slope.
Does anyone know a good way to do this?
I tried the below, which I think does what I intend by getting me the slope at the x = .05 point
[~, i] = min(abs(logitFit_long-.5)); % find value closest to x = .5
x = dataStims_long'; y = logitFit_long;
index=[i-1 i+1]; % takes the points where you want to calculate your slope (regression)
pse.coeff = polyfit(x(index),y(index),1); % calc coeff
pse.slope_line = polyval(pse.coeff,x); % calc line
Which I understand to be the slope and the y-intercept, respectively. Correct?
This looks like what I want from plotting the pse.slope_line – see dashed line below. Looks like it is the slope at x = 0.5, as it intercepts the curve at the * point
What I would then like to do is to test whether this slope is significantly different from 0, i.e., is there a slope on that line or is it flat (slope = 0)?
With the glmfit stats from above, I am able to get the significance of the slope at the y-intercept using stats.t(2) and stats.p(2), for the t and p values of the significance test of the slope (the 2ndbeta value, i.e., the ‘2’).
But I am not sure how I would do it for the slope of the line at this x = .5 point. I tried a few things but they are giving me very odd values and I assume they are incorrect.
Does anyone have any ideas?
Thank you for your help,