Statistics Toolbox | ![]() ![]() |
Compute predictions for generalized linear model
Syntax
yfit = glmval(b,X,'link
') [yfit,dlo,dhi] = glmval(b,X,'link
',stats,clev) [yfit,dlo,dhi] = glmval(b,X,'link
',stats,clev,N,offset,'const
')
Description
yfit = glmval(b,X,'
computes the predicted distribution parameters for observations with predictor values link
')
X
using the coefficient vector b
and link function '
link
'
. Typically, b
is a vector of coefficient estimates computed by the glmfit
function. The value of '
link
'
must be the same as that used in glmfit
. The result yfit
is the value of the inverse of the link function at the linear combination X*b
.
[yfit,dlo,dhi] = glmval(b,X,'
returns confidence bounds for the predicted values when you supply the link
',stats,clev)
stats
structure returned from glmfit
, and optionally specify a confidence level as the clev
argument. (The default confidence level is 0.95 for 95% confidence.) The interval [yfit-dlo, yfit+dhi]
is a confidence bound for the true parameter value at the specified X
values.
[yhat,dlo,dhi] = glmval(beta,X,'
specifies three additional arguments that may be needed if you used certain arguments to link
',stats,clev,N,offset,'const
')
glmfit
. If you fit a binomial distribution using glmfit
, specify N
as the value of the binomial N parameter for the predictions. If you included an offset variable, specify offset
as the new value of this variable. Use the same '
const
'
value ('on'
or 'off'
) that you used with glmfit
.
Example
Let's model the number of cars with poor gasoline mileage using the binomial distribution. First we use the binomial distribution with the default logit link to model the probability of having poor mileage as a function of the weight and squared weight of the cars. Then we compute a vector wnew
of new car weights at which we want to make predictions. Next we compute the expected number of cars, out of a total of 30 cars of each weight, that would have poor mileage. Finally we graph the predicted values and 95% confidence bounds as a function of weight.
w = [2100 2300 2500 2700 2900 3100 3300 3500 3700 3900 4100 4300]'; poor = [1 2 0 3 8 8 14 17 19 15 17 21]'; total = [48 42 31 34 31 21 23 23 21 16 17 21]'; [b2,d2,s2] = glmfit([w w.^2],[poor total],'binomial') wnew = (3000:100:4000)'; [yfit,dlo,dhi] = glmval(b2,[wnew wnew.^2],'logit',s2,0.95,30) errorbar(wnew,yfit,dlo,dhi);
![]() | glmfit | gname | ![]() |