필터 지우기
필터 지우기

glmfit not working: US's chances of recession

조회 수: 2 (최근 30일)
Pedro Alves
Pedro Alves 2020년 9월 18일
댓글: Star Strider 2020년 9월 19일
close all
A=[ind us2y10 rec];
X=[ind us2y10];
[logitCoef] = glmfit(X,rec,'binomial','link','logit');
yfit=[ones(359,1) X]*logitCoef;
plot(yfit);
Hello everyone!
I'm trying to estimate a logit model for the probability of recession in the US, based on a constante factor, the inddustrial production and US yield curve slope for 2y and 10y. The results are not the one supposed to be, since the model is presenting out of bounds ([0,1]) estimates.
Thanks in advance for your time in checking the script.
Cheers,
Pedro

채택된 답변

Star Strider
Star Strider 2020년 9월 19일
Use glmval to evaluate the result of the fit:
T1 = readtable('USREC.xls');
ind = T1.ind;
us2y10 = T1.us2y10;
rec = T1.rec;
X=[ind us2y10];
logitCoef = glmfit(X,rec,'binomial','link','logit');
yfit = glmval(logitCoef,X,'logit');
figure
plot(X(:,1), yfit);
grid
xlabel('ind')
ylabel('‘rec’ Fit')
sortX = sortrows(X,1) % Sort ‘X’ First
yfit = glmval(logitCoef,sortX,'logit');
figure
plot(sortX(:,1), yfit); % Cleaner-Looking Plot
grid
xlabel('ind')
ylabel('‘rec’ Fit')
producing this plot:
I am not certain what you are doing, or how to interpret this, however this plot appears to meet the [0,1] criterion.
.
  댓글 수: 4
Pedro Alves
Pedro Alves 2020년 9월 19일
It means:
1) (this formula is adequate for linear regression)
2) (this formula is adequate for logistic regression)
I adjusted the code bellow to count for 2). Note I included a constant collumn, so A = [Constant X], and I use A instead of X matrix to find the yfit. The result match with the results matlab presents in GLMVAL function.
Mr. Dobson book, An Introduction to Generalized Linear Models, is trully a good source of knowledge for the issue, and many others.
Thanks a lot for helping me, Star.
Cheers,
Pedro.
% ------ ------ Limpando a casa ------ ------
clear
close all
% ------ ------ Carregando os dados ------ ------
T1 = readtable('USREC.xls');
rec = T1.rec; % Variável explicada
ind = T1.ind; % Variável explicativa
us2y10 = T1.us2y10; % Variável explicativa
obs = T1.obs; % Período
X=[ind us2y10];
A = [ones(length(rec),1), X];
% ------ ------ Estimando ------ ------
beta = glmfit(X,rec,'binomial','link','logit');
yfit = glmval(beta,X,'logit');
yfit2 = exp(A*beta)./(1+exp(A*beta)); % *** PROBLEMA AQUI ***
% ------ ------ Plotando ------ ------
figure(1)
plot(obs,100*yfit)
title('Probabilidade de Recessão nos Estados Unidos')
ylabel('%')
hold on
plot(obs,rec*100)
hold off
figure(2)
plot(yfit2)
Star Strider
Star Strider 2020년 9월 19일
As always, my pleasure!
I appreciate the reference. I will consider getting the book for my library, since I could certainly benefit from such a source.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by