I have the following code that calculates a non-parametric regression equation (not lm) from all pairs of data. In this code 'mdns' is the median slope value and 'mdni' is the median intercept so I would then like to plot the points (all x,y pairs) from the data in a scatter plot and then plot the regression line (1) using lm from the raw data and (2) using the calculated non-parametric regression values in the standard equation y=mdni+mdns(X). I know how to do everything except this make a line in a plot from a known equation.
#Calculate pairs of all Slope values
slope<-vector()
for (i in 1:n){
for(j in 2:n){
temps<-(data1$y_book[j]-data1$y_book[i])/(data1$x_book[j]-data1$x_book[i])
if (j>i){
slope<-append(slope,temps)}
}
}
slope<-slope[!is.na(slope)]
print(slope)
mdns<-median(slope)
#Calculate the Intercept values
inter<-vector()
for (k in 1:n){
tempi<-(data1$y_book[k] - (mdns*data1$x_book[k]))
inter<-append(inter,tempi)
}
#echo results
print(inter)
mdni<-median(inter)