How to implement guide with calculating weighted quantiles using the quantreg package in r - working with unexpected results
I'm working on a project and hit a roadblock. I'm trying to calculate weighted quantiles using the `quantreg` package in R, but I keep getting unexpected results that don't match my expectations. I'm using the `rq()` function to fit a model, but when I extract the quantiles, they appear to be skewed despite using appropriate weights. Here’s a simplified version of what I’ve tried: ```r library(quantreg) set.seed(123) values <- rnorm(100) weights <- runif(100, 1, 10) # varying weights # Fitting quantile regression for 0.5 quantile (median) qr_model <- rq(values ~ 1, weights = weights, tau = 0.5) # Extracting fitted values fitted_values <- fitted(qr_model) print(fitted_values) ``` After running this, I expected the fitted values to represent the weighted median of my `values` vector. However, the output seems highly variable and doesn’t reflect the applied weights correctly. I’ve tried adjusting the `tau` parameter to different quantiles, but the results still don’t align with what I believe they should be. Additionally, I checked the version of the `quantreg` package and I’m on version 5.93. I also tried running the model without weights to compare results, which seemed to yield more consistent outputs. Is there something I'm missing in the implementation, or is it possible that the weighted quantiles are producing results that are overly sensitive to how the weights are structured? Any insights or suggestions would be greatly appreciated! Has anyone else encountered this?