I'm trying to reproduce a generalized linear model in R. The original SPSS model has distribution Gamma, link Log, with a continuous dependent variable and all independent variables categorical.
In R this should be:
glm(dependent_variable~.,data=data_for_SPSS_input,family=Gamma(link='log'))
But the coefficient estimates here don't match the ones from the SPSS output (B values) and the significant variables aren't all the same either.
The SPSS model also gives tests of model effects for the original categorical variables (rather than just the dummy coded levels) using the Wald Chi-squared test. How do I obtain these in R?
How are 'deviance', 'scaled deviance' and so on in SPSS comparable to R's null deviance and residual deviance?
Appreciate any help at all.
Best Answer
Let's try below code in R and think contrasts methods. In default, R uses
contr.treatment
in treating unordered categorical variables. (It contrasts each level with the baseline level (alphabetical first);?contr.treatment
gives you details.)In this example, baseline level is species setosa, so coefficients:
(Intercept)
andSepal.Length
are setosa's intercept and slope and theirt value
comes from the difference between setosa's intercept (or slope) and zero.(Intercept) + Speciesversicolor
is versicolor's intercept,Sepal.Length + Sepal.Length:Speciesversicolor
is its slope. Theirt value
comes from the difference between versicolor and setosa.