MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Model fitting and hypothesis testing

Asked by Arman on 17 Aug 2012

Dear all,

I have started using MATLAB statistics toolbox and have a few problems in model fitting. I have read the manual for glm, however I'm still confused with my own data. I have 3 groups of patients,with two nuisance covariates and one dependent variable. I would like to compare the measured dependent variable among three groups, controlling for two nuisance covariates. Statistics toolbox provides several functions for model fitting which is a little confusing for me. I'm confused whether I should start with glmfit or GeneralizedLinearModel and how I should proceed, whether with coeftest, glmval . I would be grateful if someone point me where I should begin and proceed.

-Arman

## Products

Answer by Tom Lane on 17 Aug 2012

The GeneralizedLinearModel interface is intended to be a step forward over glmfit, though the latter is still there. The new version, for example, will take a grouping variable as a predictor without your having to create a dummy variable for it. This version produces an object that provides methods for plotting and for testing the coefficients, among other things.

There's still a place for using glmfit, though. For instance if you wanted to do bootstrapping and didn't need the features of GeneralizedLinearModel, you'd find that glmfit is faster because it avoids any overhead in computing various parts of the fit object.

Arman on 19 Aug 2012

Thanks Tom. Would you point me in the right direction for hypothesis testing in GeneralizedLinearModel as well? An example is mentioned in my above post. I'm a little puzzled and was not able to find an example similar to my study in the documentations, so if you only show me what you would do in the mentioned example it would be great.

Tom Lane on 20 Aug 2012

Try this:

```load carsmall
d = dataset(MPG,Weight,Cylinders);
d.Cylinders = ordinal(d.Cylinders);
m = GeneralizedLinearModel.fit(d,'MPG~Weight*Cylinders')
devianceTest(m)
coefTest(m,[1 0 0 0 0 0])
coefTest(m,[0 0 0 0 1 1])
```

The first commands fit a generalized linear model to some data including a categorical predictor. It turns out this is a normal linear model but we're using the GeneralizedLinearModel class. The devianceTest function tests for significance of the model as a whole. The first coefTest function tests for the significance of the intercept, and you should see that the p-value matches the one shown in the coefficients table display.

The second coefTest function tests for the significance of the interaction term. This is similar to your case, where the term involves a three-level grouping variable and it is represented by two coefficients in the model.

I believe this is somewhat similar to your example. Here Cylinders is a categorical predictor similar to your three-group predictor. Weight could play the role of a nuisance variable.

Arman on 24 Aug 2012