rrdd

Linear RDD Plot only shows two data points


I have attempted to run the below code:

data(house)  
house_rdd = rdd_data(x=x, y=y, data=house, cutpoint=0)  
summary(house_rdd) 
plot(house_rdd) 

When I plot it, I get this, which make sense.

reg_para0 = rdd_reg_lm(rdd_object=house_rdd, slope =("same"))
summary(reg_para0)
plot(reg_para0,
     ylim=c(0,1))

However, when the regression is plotted, it only shows two observations, as seen here

Additionally, I get the warning message: "[1] "Mass points detected in the running variable.""

The graph is meant to look like this

Does anyone know potential solutions for this? I have tried "dev.off()" but that did not work.

Thanks


Solution

  • The reason for this is that the second call to plot() is creating a completely new plot rather than overlaying on the former plot.

    This should get you close to what you want (you'll need to clean up the x-axis title).

    library(rddtools)
    
    data(house)
    
    house_rdd = rdd_data(x=x, y=y, data=house, cutpoint=0)  
    plot(house_rdd, ylim=c(0,1)) 
    
    par(new=TRUE)
    
    reg_para0 = rdd_reg_lm(rdd_object=house_rdd, slope =("same"))
    plot(reg_para0, ylim=c(0,1), axes = FALSE, xlab = "", ylab = "")
    

    The par(new=TRUE) prevents the creation of a new plot.

    enter image description here