www.gusucode.com > stats 源码程序 matlab案例代码 > stats/DiagnosticPlotsForGeneralizedLinearModelsExample.m
%% Diagnostic Plots for Generalized Linear Models % This example shows how to analyze a logistic model using diagnostic % plots. %% % Input the sample data. % Copyright 2015 The MathWorks, Inc. w = [2100 2300 2500 2700 2900 3100 ... 3300 3500 3700 3900 4100 4300]'; total = [48 42 31 34 31 21 23 23 21 16 17 21]'; poor = [1 2 0 3 8 8 14 17 19 15 17 21]'; %% % The data are derived from |carbig.mat| , which contains measurements of % large cars of various weights. Each weight in |w| has a corresponding % number of cars in total and a corresponding number of poor-mileage cars % in |poor| . It is reasonable to assume that the values of |poor| follow % binomial distributions, with the number of trials given by total and the % percentage of successes depending on |w| . This distribution can be % accounted for in the context of a logistic model by using a generalized % linear model with link function log(μ/(1 - μ)) = Xb. This link % function is called |'logit'| . %% % Fit a binomial regression with a logit link function. mdl = fitglm(w,[poor total],... 'linear','Distribution','binomial','link','logit') %% % See how well the model fits the data. plotSlice(mdl) %% % The fit looks reasonably good, with fairly wide confidence bounds. %% % To examine further details, create a leverage plot. plotDiagnostics(mdl)