I am new to R and I have tried searching for an answer. I read about quantile and the "partial" argument of sort, but my apologies if I am missing something obvious. I'm wondering if there is a way of doing the following:
- Take an unsorted data set and sort it on x
- Throw away the top N data points
- Throw away the bottom N data points
- Perform a regression
Like for example, if i have 400 data points, I might want to throw away the top 5 and bottom 5 data points (not throw away values that are top 5% etc like I believe quantile would be).
Here's the code I have so far for performing the regression (some of the "if"-statements get a little complicated, so I left most of them out to try to simplify things):
Everything is in the dataframe "dependencies."
myY <- dependencies$yValue
myX0 <- dependencies$xValue
if ( timeInterval == 0 ) {
cat("A","\n")
myY <- dependencies$yValueAlternate
} else if ( timeInterval == 1 ) {
myX1 <- dependencies$xValueAlternate
}
##Add truncation step
if ( timeInterval == 0 ){
myLm <- lm(myY~myX0,dependencies)
} else if ( timeInterval == 1){
myLm <- lm(myY~myX0+myX1,dependencies)
}
print(myLm)
intercept <- coef(myLm)["(Intercept)"]
beta1 <- coef(myLm)["myX0"]
Thanks for reading and any advice/direction you can give.