dkpaster.blogg.se

Stata glm
Stata glm








This is more accurate than computing the default lower tail and subtracting from one. To obtain a p-value I specified lower.tail as FALSE. The residual deviance of 29.92 on 10 d.f. (Intercept) age25-29 age30-39 age40-49 hiEducTRUE noMoreTRUE Now try the model with these predictors > glm(cbind(using, notUsing) ~ age + hiEduc + noMore,Ĭall: glm(formula = cbind(using, notUsing) ~ age + hiEduc + noMore, Because cuse$noMore = cuse$wantsMore = "no" Recall that R sorts the levels of a factor in alphabetical order.

stata glm

(Intercept) age25-29 age30-39 age40-49 educationlowĭegrees of Freedom: 15 Total (i.e. Because all three predictors are categorical variables, they are treated automatically as factors, as you can see by inspecting the results: > lrfitĬall: glm(formula = cbind(using, notUsing) ~ age + education + wantsMore, In this case we are specifying main effects of age, education and wantsMore. In this case R adds the two columns together to produce the correct binomial denominator.īecause the latter approach is clearly the right one for us, I used the function cbind() to create a matrix by binding the column vectors containing the numbers using and not using contraception.įollowing the special symbol ~ that separates the response from the predictors, we have a standard Wilkinson-Rogers model formula. In these cases R generates a vector of ones to represent the binomial denominators.Īlternatively, the response can be a matrix where the first column is the number of “successes” and the second column is the number of “failures”. If the response is a vector, it can be numeric with 0 for failure and 1 for success, or a factor with the first level representing “failure” and all others representing “success”. With binomial data the response can be either a vector or a matrix with two columns. The first argument of the function is a model formula, which defines the response and linear predictor. First, the function is glm() and I have assigned its value to an object called lrfit (for logistic regression fit). > cuse age education wantsMore notUsing usingġ lrfit = glm( cbind(using, notUsing) ~ age + education + wantsMore,

#Stata glm full

We will illustrate fitting logistic regression models using the contraceptive use data excerpted below (and shown in full further below): age education wantsMore notUsing using The last family on the list, quasi, is there to allow fitting user-defined models by maximum quasi-likelihood.

stata glm

For example to do probits you use > glm( formula, family = binomial(link = probit))

stata glm

If you want an alternative link, you must add a link argument. There are six choices of family: FamilyĪs can be seen, each of the first five choices has an associated variance function (for binomial, the binomial variance \(\mu(1 - \mu)\), and one or more choices of link functions (for binomial, the logit, probit or complementary log-log links).Īs long as you want the default link, all you have to specify is the family name. The only parameter that we have not encountered before is family, which is a simple way of specifying a choice of variance and link functions. The basic tool for fitting generalized linear models is the glm() function, which has the folllowing general structure: > glm(formula, family, data, weights, subset.








Stata glm