Docsity

Statistical Analysis of Data: Regression and Categorical Dependent Variables - Prof. Aaron, Study notes of Introduction to Sociology

Toggle sidebar
bg1
Lecture Outline for Sociology 413/513: Sociological Research
Methods II
Aaron Gullickson
March 31, 2008
[Note: These lecture notes are not a substitute for class attendance. They are provided by the
instructor as a class aid, but the reader assumes all risk of errors, typoes, and the like.]
Contents
1 Review of OLS Regression 3
1.1 Administrative/Review ................................... 3
1.2 Missing data ........................................ 6
1.3 Weighting .......................................... 8
1.4 Mo del Selection ....................................... 9
2 Generalized Linear Models 14
2.1 Linear Probability Models and Generalized Least Squares ............... 14
2.2 Generalized Linear Models ................................. 16
2.3 Maximum Likelihood Estimation ............................. 18
3 Models for Categorical Dependent Variables 24
3.1 Odds and Probabilities ................................... 24
3.2 Logistic Regression ..................................... 27
3.3 Other types of link functions (probit) ........................... 34
3.4 Multinomial logit mo dels ................................. 38
3.5 Ordered Logit Mo dels ................................... 40
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51

Partial preview of the text

Download Statistical Analysis of Data: Regression and Categorical Dependent Variables - Prof. Aaron and more Study notes Introduction to Sociology in PDF only on Docsity!

Lecture Outline for Sociology 413/513: Sociological Research

Methods II

Aaron Gullickson

March 31, 2008

[Note: These lecture notes are not a substitute for class attendance. They are provided by the instructor as a class aid, but the reader assumes all risk of errors, typoes, and the like.]

Contents

1 Review of OLS Regression 3 1.1 Administrative/Review................................... 3 1.2 Missing data........................................ 6 1.3 Weighting.......................................... 8 1.4 Model Selection....................................... 9

2 Generalized Linear Models 14 2.1 Linear Probability Models and Generalized Least Squares............... 14 2.2 Generalized Linear Models................................. 16 2.3 Maximum Likelihood Estimation............................. 18

3 Models for Categorical Dependent Variables 24 3.1 Odds and Probabilities................................... 24 3.2 Logistic Regression..................................... 27 3.3 Other types of link functions (probit)........................... 34 3.4 Multinomial logit models................................. 38 3.5 Ordered Logit Models................................... 40

  • 4 Event History Analysis
    • 4.1 Events, rates, and relative risk
    • 4.2 Parametric survival models
    • 4.3 Semi-parametric models
    • 4.4 Discrete time approximation
    • 4.5 Event count poisson regression
  • 5 Multilevel Models
  • 6 Causal Modeling
  • 7 Factor Analysis and Structural Equation Models

· Some other good data sets are: the Current Population Survey, the Panel Study of Income Dynamics, Demographic and Health Surveys, AddHealth · Government and major NGOs (like the UN) are good sources for data. · A good place to search for data is the ICPSR · Data does not have to be survey data to be analyzed statistically - creativity is encouraged ∗ Due dates · At the end of the second week of class, students will turn in a one-page summary of their research question in broad terms. · At the end of the fourth week, students will identify a dataset that they will use for their research project. · At the end of the seventh week, students will turn in a literature review portion of their paper. · On the last day of class, students will turn in the full paper. ∗ The last week of class will provide an opportunity for each student to present their findings to the class.

  • Any other administrative questions?
  • Review of OLS Regression
  • Module Readings: Chapter 1, Chapter 2, and Appendix A (skim 2.2.2)
  • Attempting to understand how a set of independent variables affect a particular de- pendent variable: observed=structural+stochastic
  • There are different ways to view the above schematic: Causation: observed=true process+disturbance Prediction: observed=predicted+error Description: observed=summary+residual
  • Formula is always the same, but way of thinking about what you are doing is not - we will generally prefer the last method as it involves the least amount of baggage.
  • The ”observed” portion of the above equation is given by the observed values of the dependent variable, yi.
  • The structural portion of the model is given by a linear equation for the expected value of the dependent variable given certain vallues of the independent variables: yˆi = β 0 + β 1 xi 1 + β 2 xi 2 +... + βpxip
  • We saw last semester how to easily incorporate categorical independent variables, inter- action terms, and even polynomial terms into this linear equation.
  • To get the full equation you have to add on the stochastic ”tail”.

yi = β 0 + β 1 xi 1 + β 2 xi 2 +... + βpxip + i

  • Assumptions on the error term

∗ In practice, it is necessary to assume that the error term is uncorrelated with the independent variables in order to produce unbiased and consistent (estimate ap- proaches parameter in large samples) parameter estimates. ∗ We also usually usually assume that the error terms are i.i.d. (homeoskadasticity and no autocorrelation) which means that our OLS estimator is also the most efficient (smallest variance among unbiased estimators). ∗ Assuming error terms are also normally distributed is a handy, but unnecessary condition in samples of sufficient size.

  • The beta values give the intercept and slope terms which give us information about the relationship between the dependent variable and each independent variable controlling for the other independent variables.
  • We also estimate σ - the variance of the error term, to see how far the actual values of y are spread out around the predicted values.
  • These beta values are parameters for some population, but we normally have to estimate them from a sample - thus all of our rules of statistical inference come into play.

[β 0 , β 1 , · · · , βp, σ]− > [b 0 , b 1 , · · · , bp, s]

∗ The general form used to estimate these parameters can be represented in linear algebraic form as: b = (X′X)−^1 X′y Where X is the matrix of independent variables and y is the vector of the dependent variable. This formula minimizes the sum of squared residuals:

(yi − x′ iβ)^2

∗ The b values are random variables because they will differ from sample to sample. In order to make statistical inferences, we need to know the sampling distribution

  1. The missing values are missing not at random (MNAR). Given the observed data, Missingness is still a function of the unobserved observations themselves.
  • There are a variety of methods for handling missing data, but most of them are problematic.
  • Deletion. Delete cases with missing values. There are two possibilities:
  1. Casewise deletion: delete all cases with missing values on any of the variables you will use in the analysis.
  2. Pairwise deletion: delete cases for each statistical run, depending upon which variables are used in which run. This improves the sample size for most procedures, but it is very dangerous because differences across models can be the result of adding different variables or the differential deletion of cases. This method assumes the data are MCAR. It has many problems: ∗ It can produce biased results if even a moderate number of cases are missing ∗ If a large number of variables are used, small numbers of missing values per variable can add up to a lot of missing cases on the whole. This means a lot of non-missing data will be thrown out.
  • Mean Imputation: Simply substitute the mean value for all missing values. This method also assumes MCAR. This is also an extremely problematic method: ∗ Variance will be underestimated. ∗ Typically, correlations and regression coefficients will also be underestimated.
  • Imputation with dummy: Substitute any constant value for all missing values. Also include a dummy variable into the regression model indicating where imputation oc- curred. This method also assumes MCAR. ∗ The coefficient on the dummy variable measures how far off your imputation was from what would be expected based on the non-missing values. (draw a picture) ∗ It shares the problem of underestimating variance with the previous method, but regression coefficients will be estimated based only on the set of non-missing values (as if casewise deletion had been used).
  • Regression imputation: Using this technique, other variables are used to predict the value of the variable where data are missing and then the fitted values are imputed. This method assumes MAR. It is less likely to produce bias, but still will underestimate variance.
  • Random Regression imputation: This technique is like the previous one, but a ran- dom component is added to each imputation (usually based on the residuals of the model) in order to better estimate the variance. This technique
  • Multiple imputation: The problem with all of the other techniques is they do not account for imputation variability - that is the uncertainty in our estimate due to the imputations used - this variability must be reflected in the standard errors of our estimates. Multiple imputation does this by running each statistical procedure multiple times with different imputed values each time. The results from each run are then pooled to produce final estimates which account for imputation variability.

1.3 Weighting

  • As we discussed last term, many surveys use a stratified and/or cluster design. When the sam- ple drawn is no longer a simple random sample, one has to take account of each observation’s probability of being sampled.
  • The inverse of the probability of being sampled give the population weights (pi). Dividing the population weight by its mean gives sampling weights: wi = pi/¯p
  • In order to produce unbiased estimates for the population, one must account for these sampling weights. In order to estimate the mean from weighted data, for example: x¯ =

∑(w ∑i ∗^ xi) wi

  • Weights can be used in regression as well to produce unbiased estimates. Instead of minimizing the sum of squared residuals, one wants to minimize the weighted sum of squared residuals. In matrix form, we want to minimize: ∑ i

wi(yi − x′ iβ)^2 = (yi − x′ iβ)′W(yi − x′ iβ)

Where W is an nxn matrix where the diagonal gives the weights for each individual. The solution for minimizing this formula is given by: b = (X′WX)−^1 X′Wy and s^2 b = s^2 (X′WX)−^1 These weights can be implemented in STATA using the pweights command.

  • We are often interested in a comparison between models, or in including the right control variables to get the best estimate of the net effect of a particular independent variable. Model selection plays a large role in social science research - where is the right model between the null model yi = β 0 + i = μy and the saturated model?
  • Example: state-level crime data from Ehrlich (1973). The question of interest is whether rational incentives like the probability of being caught and the length of imprisonment affect crime rates. In order to assess the effects of these variables we want a model that can control for other important predictors of crime rates. Our candidate variables are: 1. percent of males aged 14- 2. south indicator variable 3. mean years of schooling 4. police expenditures in 1960 5. police expenditures in 1959 6. labor force participation rate 7. M/F sex ratio 8. population 9. nonwhites per 1000 population
  1. unemployment rate of urban males 14-
  2. unemployment rate of urban males 35-
  3. GDP
  4. income inequality
  5. probability of imprisonment
  6. average time served in state prisons The full model with all variables and Ehrlich’s chosen model are shown in the table. It is clear that the effects are much smaller in the full model than in the model Ehrlich chose, which makes us wonder if his effects are measured using the right model.
  • We assess the goodness of fit of the OLS model generally by R^2 , but we have to balance goodness-of-fit with parsimony.
  • We can always get a better fit (or at least not a worse fit) by adding more variables to the model, so R^2 is not helpful in and of itself. One technique for balancing parsimony is to use the adjusted R^2 : adj.R^2 = 1 − ( (^) n −n^ −p −^1 1 )( SSESST ) The expression before the sum of squares ratio will always be less than one when k is greater than zero, so this expression ”penalizes” R^2 for including more variables into the model. We could try choosing the model which maximizes our adjusted R^2.
  • Another technique is to proceed in a stepwise fashion. There are three basic approaches:
    1. Forward Selection. Begin with the variable with the highest single R^2 value. Next search for the variable to add which will lead to the next greatest increment in R^2 , and continue this process until all possible variables are added or some stopping criterion is reached (typically that the next added value is not stat. sig. at some level).
    2. Backward Selection. Begin with the full model. Remove one variable based on some criterion (typically the smallest t-value). Continue this process until all remaining vari- ables are above some pre-established threshold.
    3. Stepwise Selection. Begin like forward selection, but at the end of each step, remove any variables that have fallen below a certain threshold (typically on the t-value) before moving forward another step.
  • These methods can sometimes give different results.
  • Elimination is purely on statistical significance.
  • What about things like interactions or polynomial terms?
  • Bayesian Information Criterion (BIC)
    • The mathematics behind BIC are fairly complex, but it is fairly intuitive to understand in practice - In addition it can be applied to a wide range of linear models besides OLS regression with the same interpretation, making it very versatile.
    • For OLS regression, BIC’ (the punctuation indicates our comparison is the null model) is calculated as: BIC′^ = n log(1 − R^2 ) + p log(n) This equation balances parsimony and goodness-of-fit.
    • BIC′^ is implicitly compared to the null model. The smaller BIC′^ is, the better. If BIC′^ < 0, then the current model is preferred over the null model.
  • BIC′^ can also be used to compare two non-null models, even if they are non-nested. The model with a smaller (generally, more negative) BIC′^ is preferred.
  • The best approach depends on what you are doing with the model.
  • Its best to have a theoretical reason for fitting the model as you are, rather than just throwing in variables randomly and seeing what happens (monkeys and computers can do that–you are supposed to be the brains of the operation)
  • Generally we are interested in a particular variable or a small set of variables and the others are included as controls. Even if these controls look not statistically distinguishable from zero, it may still be good to include them in the equation. Show the full model and let your readers make their own decisions.
  • In some social science research, the key issue is a comparison of models which present competing explanations of the process. In these cases, model selection is very important, and you should carefully consider your options. Generally it is best here to present several techniques.

2 Generalized Linear Models

2.1 Linear Probability Models and Generalized Least Squares

  • So far we know how to use both continuous and categorical variables to predict continuous variables. What if we want to predict categorical variables? (i.e. use them as the dependent variable) In sociology much of what we care about comes as categorical not continuous.
  • Let’s say we are interested in explaining why individuals fall into different categories of a dichotomous variable. - Lets take our titanic example. Let yi equal 1 if the person survived the titanic and 0 if the person did not. Let’s look at how survivorship varied as a function of the fare (in british pounds) that a person payed: Variable Coefficient Constant 0.3058 (19.27) Fared paid (in british pounds) 0.0023 (9.10) - What do the intercept and slope mean in this particular case? The slope is the the change in your probability associated with paying one more pound for your fare. In this case, for every extra pound paid, your probability of surviving goes up by about 0.22%. Those who paid no fare are estimated to have a probability of survivorship of 30.58%. This is called the Linear Probability Model. - The IQR for fare payed was approximately 17 pounds and the maximum fared payed was 512 pounds. so it seems that fare had a fairly sizeable effect on survivorship, which is not surprising given that fare is a good proxy for the social class of passengers. - There are two problems with the linear probability model. ∗ The i.i.d. assumption is violated. The variable yi is distributed as a bernoulli variable. The variance of a bernoulli variable depends on the true probability of a ”yes.” Thus the variance of the error term will not be constant. In technical terms, this is the problem of heteroskadasticity. ∗ The linear probability model can produce fitted values that are outside the range of [0,1]. Take the passenger who paid the highest fare.

.3058 +. 0023 ∗ 512 = 1. 48

  • The first problem can be dealt with using the technique of generalized least squares.

∗ FGLS can usually be improved by iterating the result, when it becomes Iteratively Reweighted Least Squares (IRLS).

  1. Run linear probability model using OLS. Get the predicted values of pi from this run.
  2. Use ˆpi in the weighting matrix to run an FGLS. Get the predicted values of pi from this run.
  3. Use the updated ˆpi in the weighting matrix of another FGLS. Get the predicted values of pi from this run.
  4. Repeat step 3 until the estimates of β no longer change very much. ∗ Let’s try it out on our titanic data: Coefficient 1 2 3 4 5 6 7 8 Intercept 0.30588 0.31292 0.3074 0.30987 0.30857 0.30921 0.30888 0. Slope 0.00229 0.00186 0.00211 0.00199 0.00205 0.00202 0.00204 0. Coefficient 9 10 11 12 13 14 15 Intercept 0.30896 0.30901 0.30898 0.30899 0.30899 0.30899 0. Slope 0.00203 0.00203 0.00203 0.00203 0.00203 0.00203 0. ∗ You can still run into problems with FGLS if your estimated values of pi extend beyond the range of [0,1] because it can lead to negative weights. In this example, I had to ”hack” a few observations that were outside the range by substituting the maximum value observed within the range.
  • GLS can resolve the problem of error terms which are not i.i.d., but it still can produce fitted values outside the range of the dependent variable. This second problem requires us to move to Generalized linear models.

2.2 Generalized Linear Models

  • Our OLS regression equation is: yi = β 0 + β 1 xi 1 + β 2 xi 2 +... + βpxip + i
  • For this model, we assume:
    1. The relationship between the independent variables and dependent variables is a linear function.
    2. The errors are distributed identically with a constant variance.
  • These assumptions become problematic for categorical dependent variables because:
  1. Predictions can fall outside the range of the of the dependent variable (linearity problem)
  2. The variance of the error term is often related to the expected value ( ˆyi) for each ob- servation (true for both binomial and poisson distributed variables), meaning we have non-constant variance, or heteroskadasticity (i.i.d. problem). To put it more formally: V (y|x) = V (ˆy) = f (ˆy)
  • The generalized linear model deals with this problem by two extensions of the linear regression model.
  1. We have a link function that relates our linear function of the independent variables not to yi directly, but rather to some function of yi, given by g(yi). The idea of the link function is to expand the range of y from some limited range to the range of (−∞, ∞).
  • Take our titanic example. We are interested in modeling pi, each individual’s prob- ability of survival. However, pi is bounded by 0 and 1.
  • We can improve this by looking at the odds of survival rather than the probability of survival. (we will discuss odds in more depth in the next module) oi = (^1) −pi p i
  • While probabilities are bounded by 0 and 1, odds are bounded by 0 and ∞. This is an improvement, but we still could get results outside of the lower bounds. We can resolve this problem by logging the odds: logit(pi) = log(oi) = log(pi(1 − pi))
  • This is called the logit transformation. Rather than related our x variables linearly to pi, we relate them linearly to the logit transformation of pi.
  1. Rather than assume i.i.d., we specify a particular error distribution for our errors. This distribution is based on what we think is driving the categorical distinctions we observe in y. (i.e. binomial for dichotomous variables)
  • Once again from our example. We believe each observation has an underlying pi, but we actually only observe ones and zeroes (success and failures). Therefore, the error distribution from our predicted to actual values will be given by the bino- mial/bernoulli distribution. yi is given by binom(pi) V (pi) = pi(1 − pi)

x

y

y=5+28x+7x^

∗ Every function has a derivative. The derivative is basically the exact slope of the function at x. df (x) dx = 28^ −^14 x ∗ Local minimums and maximums of the function f (x) will occur when the slope is zero. (show graphically).

0 = 28 − 14 x 14 x = 28 x = 2

∗ You can tell if it is a local minimum or maximum by looking at the second derivative, which is the derivative of the derivative. If this is positive at that point, then it is a minimum. If it is negative, then it is a maximum. d^2 f (x) dx =^ −^14

∗ So this is a maximum.

  • The logic of maximum likelihood estimation is as follows:
    1. We have some process governed by some parameter(s), (say θ) which generates a set of observed data (x 1 , x 2 ,... , xn or something).
    2. We ask what is the likelihood, given the process, that we observe the given data? This leads to a likelihood function, L(θ).
    3. The trick is we don’t know θ. Rather it is usally the data we have and θ that we want to estimate. We choose a θˆ such that it maximizes our likelihood function given the data.
  • Example with a binomial proportion.
    • We have observed the outcome from a series of n coin tosses. From this coin toss, we have observed x heads. n and x are our observed data.
    • We know that the process of generating heads on coin tosses is a binomial process, because we only have two possible outcomes, and the probability p is the same on each coin toss. p (the probability of a heads on a single coin toss) is our unknown parameter.
    • Since this is a binomial process our likelihood of observing a particular number of heads in n trials is given by the following likelihood function:

L(p) =

(n x

px(1 − p)n−x

(review this formula a bit)

  • We don’t know the value of p, but we want to estimate it by choosing ˆp that maximizes L(p) for the given n and x.
  • For particular values of n and p, we could get ˆp by trial and error, but that might take a long time. A computer might simplify it. Let’s take the example, where x = 13 and n = 50. We can use the computer to calculate the likelihood functions for every p at intervals of 0.01 from 0 to 1.