Time Series Data

I've uploaded a couple of files you can use for time series regression. To load the first dataframe, use:

The dependent variable, Y, is maternal mortality (deaths per 100,000 live births) and the independent variable, X, is number of physicians (per 1,000 population).

To use the second, use:

Feedback Requested

Please take a few minutes to complete a qualitative course feedback report. Thank you!

Time Series III: time series regression models


# Let's look at two time series. In this data frame,
# Y is the monthly unemployment rate for women, 20+ yrs,
# and X is the same rate for men, 20+.

# We can ask whether or not the unemployment rate for men predicts
# the unemployment rate for women. We might use regular linear
# regression:

Time Series II: Moving Average, Autoregresive


# Let's look at a time series
data(airmiles, package="datasets")

# It appears that there is a trend. We can try to fit a model
# of the effect of time.

# Now, let's model a quadratic function for the trend.

# We'll look at autocorrection.
acf(airmiles,main="ACF airmiles")
acf(airmiles,type="p",main="ACF airmiles")
plot(y=airmiles, x=zlag(airmiles), type="p")

# We'll look at moving average.
# In R, you can create your own functions

Time Series I: Trends

We'll discuss first the nature of different data methods (cross-sectional, longitudinal, panel, time series).

With time series data, we need to become familiar with some basic terms and concepts before we can discuss how to analyze it.
* stochastic process
* "random walk"
* moving average
* stationarity
* autocorrelation
* differencing

The process of modeling time series data has three parts:
a) specification
b) fitting
and c) diagnostics.

R script:
# http://www.courseserve.info/files/SOCY7113trends.r
# SOCY7113trends.r

# Load libraries.

Longitudinal Analysis (Mixed Effects Models)


# Load libraries.

# Load the data file.

# We can look at the variables with the summary() function.
# In this file, time is measured with 't' and 'statenum' refers
# to the cases.

# We'll first test the random intercept model.

# Now we'll test the random intercept and slope model.

Event History Analysis (Survival Analysis)

* data type
* censored cases
* "survival" function
* "hazard" function
* log-rank test for differences in survival functions
* Cox's regression

R code:
# http://www.courseserve.info/files/SOCY7113survival.r
# SOCY7113survival.r

# Load libraries.

# Open the data file.
data("standford2", package="survival")

# We'll create groups by dividing the cases into "older than median" and "younger than median"
for (i in 1:length(stanford2$age)) { if(stanford2$age[i] > median(stanford2$age)) stanford2$group[i]=1 else stanford2$group[i]=0}

Latent Structure

# We're going to compare three techniques for investigating latent structure:
# PCA, MDS, and k-means clustering.


# V085064D feminists
# V085064E federal government
# V085064F Jews
# V085064G liberals
# V085064H middle class people
# V085064J labor unions
# V085064K poor people
# V085064M military
# V085064N big business
# V085064P people on welfare
# V085064Q conservatives
# V085064R working class people
# V085064S environmentalists
# V085064T Supreme Court
# V085064U gays and lesbians
# V085064V Asian-Americans
# V085064W Congress
# V085064Y Blacks


This is the third method for investigating latent structure.

# We're going to look at k-means clustering using a subset of variables from the ANES,
# the feeling thermometers for various social groups, to look for latent structure
# that might underlie grouping of these social objects into clusters.
# To facilitate our interpretation of the clusters, I've listed the variables here:

# V085064D feminists
# V085064E federal government
# V085064F Jews
# V085064G liberals
# V085064H middle class people
# V085064J labor unions
# V085064K poor people
# V085064M military

Principal Component Analysis

Our last statistical tool is principal component analysis, a kind of exploratory factor analysis. It is a data reduction strategy. We use patterns of covariance to identify a number of underlying "factors" -- in this case, principal components -- and try to interpret these as indicating latent factors. We can then use these principal components in place of the original variables to do further analysis, such as linear regression.


Syndicate content