Clear Filters
Clear Filters

How do I predict x for a given value of y using glmval?

4 views (last 30 days)
Hello!
I am using glmfit to fit a logistic regression to my data, where y varies from 0 to 1 and x can be from 0 to 1000s.
[logitCoef, dev, stats] = glmfit(xarray, yarray, 'binomial','logit');
Then I can use glmval to predict the values of y for a given x
logitFit = glmval(logitCoef,xarray,'logit');
Now, I want to use this fitted function to predict the value of x when y is 0.5. How can I do this?
Thank you for help!

Accepted Answer

Star Strider
Star Strider on 3 Apr 2022
Using code from the documentation as an example —
x = [2100 2300 2500 2700 2900 3100 ...
3300 3500 3700 3900 4100 4300]';
n = [48 42 31 34 31 21 23 23 21 16 17 21]';
y = [1 2 0 3 8 8 14 17 19 15 17 21]';
b = glmfit(x,[y n],'binomial','Link','probit');
yfit = glmval(b,x,'probit','Size',n);
yval = 0.5;
xval = interp1(yfit./n, x, yval)
xval = 3.1958e+03
figure
plot(x,y./n,'o',x,yfit./n,'-')
hold on
plot(xval, yval, 'm+', 'MarkerSize',15)
hold off
text(xval, yval, sprintf(' (%0.2f, %0.2f)', xval, yval), 'Horiz','left', 'Vert','middle')
.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!