Regression Thomas J. Leeper Department of Political Science and - - PowerPoint PPT Presentation

regression
SMART_READER_LITE
LIVE PREVIEW

Regression Thomas J. Leeper Department of Political Science and - - PowerPoint PPT Presentation

Models Objects and Output Interactions Regression Thomas J. Leeper Department of Political Science and Government Aarhus University November 14, 2013 Models Objects and Output Interactions Models Objects and Output Interactions Models


slide-1
SLIDE 1

Models Objects and Output Interactions

Regression

Thomas J. Leeper

Department of Political Science and Government Aarhus University

November 14, 2013

slide-2
SLIDE 2

Models Objects and Output Interactions

slide-3
SLIDE 3

Models Objects and Output Interactions

1

Models

2

Objects and Output

3

Interactions

slide-4
SLIDE 4

Models Objects and Output Interactions

1

Models

2

Objects and Output

3

Interactions

slide-5
SLIDE 5

Models Objects and Output Interactions

Model Formulæ

Express relationships as a formula Typically: y x1 + x2 Interactions: y x1 * x2 y x1 + x2 + x1:x2 Formula is an object

slide-6
SLIDE 6

Models Objects and Output Interactions

Try on your own

Understand formulae: “Model Formulae”

slide-7
SLIDE 7

Models Objects and Output Interactions

Questions so far?

slide-8
SLIDE 8

Models Objects and Output Interactions

Running a regression

We already ran regressions earlier Let’s understand what we did

slide-9
SLIDE 9

Models Objects and Output Interactions

The regression from earlier

lm3_1 <- lm(thresh~threat + fragdum, data = cis) lm3_2 <- lm(thresh~threat + fragdum, data=cis[cis$oursmpl==1,]) lm3_3 <- lm(thresh~threat13 + fragdum, data=cis[cis$oursmpl==1,]) lm3_4 <- lm(thresh~stthroct2 + fragdum, data=cis[cis$oursmpl==1,])

slide-10
SLIDE 10

Models Objects and Output Interactions

Running a regression

The linear regression function is lm Specify a formula and a place to look for data The result is an object of class “lm”

slide-11
SLIDE 11

Models Objects and Output Interactions

The regression from earlier

lm3_1 <- lm(thresh~threat + fragdum, data = cis) lm3_2 <- lm(thresh~threat + fragdum, data=cis[cis$oursmpl==1,]) lm3_3 <- lm(thresh~threat13 + fragdum, data=cis[cis$oursmpl==1,]) lm3_4 <- lm(thresh~stthroct2 + fragdum, data=cis[cis$oursmpl==1,])

slide-12
SLIDE 12

Models Objects and Output Interactions

1

Models

2

Objects and Output

3

Interactions

slide-13
SLIDE 13

Models Objects and Output Interactions

Printing

When we run a regression, we get some default

  • utput:

lm(thresh~threat + fragdum, data = cis)

slide-14
SLIDE 14

Models Objects and Output Interactions

Printing

When we run a regression, we get some default

  • utput:

lm(thresh~threat + fragdum, data = cis) This doesn’t print if we store the results: lm3_1 <- lm(thresh~threat + fragdum, data = cis)

slide-15
SLIDE 15

Models Objects and Output Interactions

Printing

When we run a regression, we get some default

  • utput:

lm(thresh~threat + fragdum, data = cis) This doesn’t print if we store the results: lm3_1 <- lm(thresh~threat + fragdum, data = cis) But we can see the results again, once stored, by simply calling: lm3_1

slide-16
SLIDE 16

Models Objects and Output Interactions

Structure and summary

Structure: str(lm3_1) Names: names(lm3_1) Summary: summary(lm3_1)

slide-17
SLIDE 17

Models Objects and Output Interactions

Coefficients

Coefficients: coef(lm3_1) lm3_1$coef coef(summary(lm3_1)) summary(lm3_1)$coef

slide-18
SLIDE 18

Models Objects and Output Interactions

Try on your own

Understand OLS coefficient plotting: “OLS Coefficients”

slide-19
SLIDE 19

Models Objects and Output Interactions

Questions so far?

slide-20
SLIDE 20

Models Objects and Output Interactions

Fitted values and residuals

lm3_1$fitted lm3_1$resduals predict(lm3_1)

slide-21
SLIDE 21

Models Objects and Output Interactions

Try on your own

Understand model fit: “OLS Diagnostic Plots” “Regression fit”

slide-22
SLIDE 22

Models Objects and Output Interactions

Questions so far?

slide-23
SLIDE 23

Models Objects and Output Interactions

Writing Output to Word

Writing a CSV Using the rtf package: install.packages("rtf") library(rtf)

slide-24
SLIDE 24

Models Objects and Output Interactions

Try on your own

Output results to Word: “Word output”

slide-25
SLIDE 25

Models Objects and Output Interactions

Questions so far?

slide-26
SLIDE 26

Models Objects and Output Interactions

1

Models

2

Objects and Output

3

Interactions

slide-27
SLIDE 27

Models Objects and Output Interactions

Let’s work together

“Binary interactions” “Continuous interactions”

slide-28
SLIDE 28