NOW AVAILABLE: Essentials of Poltical Analysis 7e | R Companion 4e | SPSS 7e | Stata 5e | Excel 1e 🎵
NOW AVAILABLE: Essentials 7e | R Companion 4e | SPSS 7e | Stata 5e | Excel 1e 🎵
NOW AVAILABLE: Essentials 7e | More Textbooks 🎵

Run R Code Example Online

# 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")