• No results found

QPM Lab 2: Data Visualization & Descriptive Statistics in R and R Commander

N/A
N/A
Protected

Academic year: 2021

Share "QPM Lab 2: Data Visualization & Descriptive Statistics in R and R Commander"

Copied!
19
0
0

Loading.... (view fulltext now)

Full text

(1)

QPM Lab 2:

Data Visualization & Descriptive Statistics

in

R

and

R

Commander

Viktoryia Schnose & Betul Demirkaya

Department of Political Science

Washington University, St. Louis

September 4, 2013

(2)

A Reminder From Last Class

1

Open

R

2

Write the following in the command line:

library(Rcmdr)

3

This way, you open the package from the

R

library. It does

not

open

automatically.

4

A new

window

should have opened. This is

R commander

.

5

Go to the website for QPM.

6

Open the Class Datasets.

(3)

Goals for the Class

Reading a dataset & viewing the dataset with

R commander

Re-coding a variable to a factor

Descriptive Statistics with

R commander

Bar graphs with

R commander

(4)

Reading Data with

R

: Answering Two Questions

1

What type of file do you have?

.csv

= comma separated values

.txt

= text file

.dta

= STATA file

.spss

= SPSS file

2

Where is the file?

Saved in your computer

Online in a url

(5)

Reading Data with

R

:

.csv

or

.txt

STEP 1: What type of file are we using for the homework?

(6)

Reading Data with

R

:

.csv

or

.txt

STEP 2: Where is the file for the dataset for this week’s HW?

See Appendix for how to enter the URL.

(7)

Brazil Dataset: Viewing the Dataset

Active

Dataset

Variable

name

Observation

number

Click here

Wednesday, September 7, 2011
(8)

Brazil Dataset: Converting

vote

variable into

a factor = qualitative variable

(9)

Brazil Dataset: Converting

vote

variable into

a factor = qualitative variable II

Select

vote

variable.

(10)

Brazil Dataset: Converting

vote

variable into

a factor = qualitative variable III

Specify what each numeric value means (read the codebook).

Wednesday, September 7, 2011

(11)

Brazil Dataset: Frequency Distribution for

vote

variable

Statistics

Summaries

Frequency distributions

(12)

Brazil Dataset: Bar Graph for

vote

variable (frequency)

Graphs

Bar Graph

vote

no yes vote F re qu en cy 0 200 400 600 800

See Appendix for another way of presenting the same data.

(13)

In class assignment

Break into groups of 3 or 4 individuals

Fill out the sheet. ASK QUESTIONS.

If you finish early, try to draw a bar graph for

vote

variable that

shows probabilities. See Appendix for help.

(14)

Appendix: Table of Contents

Using

R

&

R Commander

Reading

.csv

or

.txt

files from the internet

Frequency distribution: Difference between

R

script and

R

output

Another graph for vote variable showing probability

R

code to obtain the bar graph with probability

(15)

Using

R

&

R Commander

Drop down

menus

Toolbar

Script Window

:

Here you will see R commands

generated by the GUI.

You can write commands here.

Select them by highlighting them and press ‘Submit’

Output Window

:

Dark Blue

: printed output

Red

: command used

Message Window:

Red

- Error Message

Green

- Warning

Dark Blue

- Other

information

Thursday, September 1, 2011
(16)

Reading Data with

R

:

.csv

or

.txt

From the Internet

STEP 3: Writing down the

URL

for the Brazil dataset.

Prof. Montgomery’s website

(17)

Difference between R Script and R Output

Output

Script

Wednesday, September 7, 2011

(18)

Brazil Dataset: Bar graph for

vote

variable (probability)

no yes

Did you vote in the last presidential election?

Pro ba bi lit y 0 20 40 60 80

(19)

Brazil Dataset: Bar graph for

vote

variable (probability)

This is how to modify the code to obtain the previous plot.

barplot(table(brasil$vote)*100/sum(table(brasil$vote)),

xlab = "vote", ylab="Probability")

References

Related documents

The spring brought changes for Samantha. The school’s ITRT had started visiting all of the class- rooms more, not just the teachers who actively sought out help. Her preschool

Four protocols were evaluated: the Wireless Internet Routing Protocol (WIRP) [2]; a Link State (LS) algorithm with constrained LS updates, based on ideas presented as part of the

The research questions are respectively focusing at; relevant Dutch and Czech environmental factors concerning the road transport market, the company Cargospol,

Selectman Crowley moved that the Board of Selectmen authorize remote participation in public meetings by members of all Town of Medway public bodies in accordance with the

Our experience indicates successful organizations begin with development of an effective customer engagement strategy, which drives development of an enabling operational

We then verify that the mass and spin parameters of the final black hole, as predicted from the binary ’s inspiral signal, are consistent with the final parameters inferred from

Funding for the DES Projects has been provided by the United States Department of Energy, the United States National Science Foundation, the Ministry of Science and Education of

The effective-one-body (EOB) approach to the general relativ- istic two-body problem [5 –8] is a powerful analytical tool that reliably describes both the dynamics and