Documentation Center

  • Trial Software
  • Product Updates

glmval

Generalized linear model values

Syntax

yhat = glmval(b,X,link)
[yhat,dylo,dyhi] = glmval(b,X,link,stats)
[...] = glmval(...,param1,val1,param2,val2,...)

Description

yhat = glmval(b,X,link) computes predicted values for the generalized linear model with link function link and predictors X. Distinct predictor variables should appear in different columns of X. b is a vector of coefficient estimates as returned by the glmfit function. link can be any of the strings or the custom-defined link functions used as values for the 'link' name-value pair argument in the glmfit function.

    Note:   By default, glmval adds a first column of 1s to X, corresponding to a constant term in the model. Do not enter a column of 1s directly into X. You can change the default behavior of glmval using the 'constant' parameter, below.

[yhat,dylo,dyhi] = glmval(b,X,link,stats) also computes 95% confidence bounds for the predicted values. When the stats structure output of the glmfit function is specified, dylo and dyhi are also returned. dylo and dyhi define a lower confidence bound of yhat-dylo, and an upper confidence bound of yhat+dyhi. Confidence bounds are nonsimultaneous, and apply to the fitted curve, not to a new observation.

[...] = glmval(...,param1,val1,param2,val2,...) specifies optional parameter name/value pairs to control the predicted values. Acceptable parameters are:

ParameterValue

'confidence' — the confidence level for the confidence bounds

A scalar between 0 and 1

'size' — the size parameter (N) for a binomial model

A scalar, or a vector with one value for each row of X

'offset' — used as an additional predictor variable, but with a coefficient value fixed at 1.0

A vector

'constant'
  • 'on' — Includes a constant term in the model. The coefficient of the constant term is the first element of b.

  • 'off' — Omit the constant term

'simultaneous' — Compute simultaneous confidence intervals (true), or compute non-simultaneous confidence intervals (default false)true or false

Examples

expand all

Fit Generalized Linear Model with Probit Link

Enter sample data.

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]';

Each y value is the number of successes in corresponding number of trials inn, and x contains the predictor variable values.

Fit a generalized linear model for y on x using a probit link function.

b = glmfit(x,[y n],'binomial','link','probit');

Compute the estimated number of successes and plot the observed and estimated percent success versus the x values.

yfit = glmval(b,x,'probit','size',n);
plot(x, y./n,'o',x,yfit./n,'-','LineWidth',2)

Use Custom-defined Link Function

Enter sample data.

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]';

Each y value is the number of successes in corresponding number of trials in n, and x contains the predictor variable values.

Now define three function handles, created using @, that define the link, the derivative of the link, and the inverse link for a probit link function, and store them in a cell array.

link = @(mu) norminv(mu);
derlink = @(mu) 1 ./ normpdf(norminv(mu));
invlink = @(resp) normcdf(resp);
F = {link, derlink, invlink};

Fit a generalized linear model for y on x using the link function you defined.

b = glmfit(x,[y n],'binomial','link',F);

Compute the estimated number of successes and plot the observed and estimated percent success versus the x values.

yfit = glmval(b,x,F,'size',n);
plot(x, y./n,'o',x,yfit./n,'-','LineWidth',2)

References

[1] Dobson, A. J. An Introduction to Generalized Linear Models. New York: Chapman & Hall, 1990.

[2] McCullagh, P., and J. A. Nelder. Generalized Linear Models. New York: Chapman & Hall, 1990.

[3] Collett, D. Modeling Binary Data. New York: Chapman & Hall, 2002.

See Also

| | |

Was this topic helpful?