FIND DATA: By Author | Journal | Sites   ANALYZE DATA: Help with R | SPSS | Stata | Excel   WHAT'S NEW? US Politics | Int'l Relations | Law & Courts
   FIND DATA: By Author | Journal | Sites   WHAT'S NEW? US Politics | IR | Law & Courts
Run R Code
About This Page
This page features live demonstrations of the R Statistics Program used for political science research.
  • To run example, click the Run button.
  • To copy example code, click the Copy button.


See More R Demos
Run R Code in Your Web Browser
# This sample code creates objects, performs computations, and produces a graphic.
# Try changing the value of thisIntercept and thisSlope 

# Assigning Values to Objects
thisIntercept = 0
thisSlope = -1
simDataX = runif(20, -10, 10)

# Performing Computations with Objects
simDataY = thisIntercept + thisSlope*simDataX + runif(20, -10, 10)

# Creating Graphics
plot(x="", y="", xlim=c(-10,10), ylim=range(simDataY), xlab="X Values", ylab="Y Values")
abline(a=thisIntercept, b=thisSlope)
points(x=simDataX , y=simDataY, col="red")
abline(lm(simDataY ~ simDataX), col="red")
Watch & Learn
thumbnail preview
â–º
i
From Roger Peng (6:25).
 The ggplot2 Plotting System, Part 1a
thumbnail preview
â–º
i
From Phil Chan (5:38).
 How to Change the Baseline (Reference) Category in Regression
MORE VIDEOS: See Video Channels for more political science videos!
LEARN HOW: Watch Lecture Videos for Essentials of Political Analysis, Video Tutorials for R, Stata, SPSS, and Excel