Regression Analysis – R Code

This is an R code on regression analysis: a linear and a probit and logit model are being implemented. Logistic regression is useful when predicting a binary outcome using a set of continuous predictive variables. The time series are randomly created so no meaningful results can be expected.

# clear environment and console
rm(list = ls())
cat("\014")

# create random series for the independent variable (var1) and dependent
# variables (var2 var3)
v1 = data.frame(var1 = runif(100, 20, 120))
v2 = data.frame(var2 = runif(100, 20, 120))
v3 = data.frame(var3 = runif(100, 20, 120))

# concatenate the time series
v = c(v1,v2,v3)

# run a linear regression
reg1 = lm(var1 ~ ., data = v)
summary(reg1)

# create random series for the independent variable (var4, bounded between 0 and 1)
# and dependent variables (var5 var6)
v4 = data.frame(var4 = runif(100, 0, 1))
v5 = data.frame(var5 = runif(100, 20, 120))
v6 = data.frame(var6 = runif(100, 20, 120))

# concatenate the time series
vv = c(v4,v5,v6)

# run probit regression
reg2 = glm(var4 ~ ., family = quasibinomial(link = "probit"), data = vv)
summary(reg2)

# run logit regression
reg3 = glm(var4 ~ ., family = quasibinomial(link = "logit"), data = vv)
summary(reg3)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s