create a regression discontinuity model in r

Here is an example of how to create a regression discontinuity model in R using the Rdpack package:

# Load required packages
library(Rdpack)

# Load example data set (cars)
data(cars)

# Create a scatter plot of the data
plot(cars$speed, cars$dist, main = "Stopping Distance vs. Speed", 
     xlab = "Speed (mph)", ylab = "Stopping Distance (ft)")

# Create a regression discontinuity model
model <- rdd_data(cars$speed, cars$dist, cutpoint = 20, verbose = FALSE)
summary(model)
379 chars
14 lines

This code first loads the Rdpack package and the example data set cars. It then creates a scatter plot of the data to visualize any potential discontinuity in the relationship between speed and stopping distance. Finally, it uses the rdd_data function to fit a regression discontinuity model with a cutpoint of 20 (i.e. where the discontinuity is expected to occur). The model is then summarized using the summary function.

gistlibby LogSnag