0

Does anyone know how to fit a quadratic (or higher order) model on a continuous variable and do quantile regression on it in R? Additionally, how do you tell what level of tau fits the data better?

The values for "den" are fish densities (count/m^3) and salinity = salinity (ppt). The full dataset is 1500 observations and I'd like to predict fish density using salinity. A plot with all the data looks semi-quadratic, but I'd like to compare that fit to others using quantile regression. I just can't figure out how to make the relationship in the model non-linear. Is it den ~ salinity + salinity^2?

df <- structure(list(den = c(0, 12, 8.33, 5, 0, 0, 1, 1.33, 0, 3), salinity = c(37, 35, 36, 39, 36, 37, 35, 38, 36, 37)), row.names = c(86L, 
            240L, 394L, 548L, 702L, 856L, 1010L, 1164L, 1318L, 1472L), class = "data.frame")
    
quantreg75 <- rq(den ~ salinity, data=rain, tau=0.75)
5
  • 1
    (1) You could try rq(den ~ poly(salinity, 2), data = rain, tau = 0.75). (2) Your data is named rain not df. Commented Nov 18, 2021 at 20:47
  • Right, ya, rain is the original dataframe, I just made up df. I have some NA's in salinity and I get this error: Error in poly(salinity, 2) : missing values are not allowed in 'poly' Commented Nov 18, 2021 at 20:56
  • You could remove the NA values first. Commented Nov 18, 2021 at 20:57
  • I get 2 estimates for some reason, any ideas? One for poly(salinity, 2)1 and poly(salinity, 2)2. Commented Nov 18, 2021 at 21:08
  • 1
    it's a polynom of grade two, so there is salinity and salinity^2. Commented Nov 18, 2021 at 21:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.