www.gusucode.com > stats 源码程序 matlab案例代码 > stats/FitaGeneralizedLinearModelExample.m
%% Fit a Generalized Linear Model % Fit a logistic regression model of probability of smoking as a function % of age, weight, and sex, using a two-way interactions model. %% % Load the |hospital| dataset array. load hospital ds = hospital; % just to use the ds name %% % Specify the model using a formula that allows up to two-way interactions. modelspec = 'Smoker ~ Age*Weight*Sex - Age:Weight:Sex'; %% % Create the generalized linear model. mdl = fitglm(ds,modelspec,'Distribution','binomial') %% % The large $p$-value indicates the model might not differ statistically % from a constant.