240 likes | 639 Views
Quantile regression- a very brief introduction. Marian Scott NERC workshop, University of Glasgow December 2013. What shall we cover?. What do we mean by a quantile? Quantile regression Inference Other resources.
E N D
Quantile regression- a very brief introduction Marian Scott NERC workshop, University of Glasgow December 2013
What shall we cover? • What do we mean by a quantile? • Quantile regression • Inference • Other resources
Usual Regression: response Y, considered as a function of explanatory variables x1,x2,...,xn, more formally, the standard regression is for the conditional mean of the response variable E(Y|X) = f(x1,x2,...,xn). However, we can build regression models for other parts of the distribution of Y, namely other quantiles, and hence the name quantile regression. Can be very useful when interested say in extremes of temperature, or rainfall since extremes are high quantiles of a distribution A quantile regression model
QY (|X) by this we mean the conditional quantile of the response variable that we wish to model. In the standard regression model, QY (0.5|X) is for the median (rather than the mean), but is probably closest to the standard regression that you will be familiar with. QY (0.9|X) is the 90th percentile of the Y distribution, conditional on X. Or 90% of the values for Y are less than or equal to the specified function of X. What is a quantile?
QY (|X) is a linear function, the parameter values are now also indexed by , e.g. 0 ()X0 + 1 ()X1 + 2 ()X2 Parameter estimates in linear quantile regression models have the same interpretation as those in other linear models, namely the rate of change in the response quantile of interest for unit changes in the explanatory after adjustment for the other explanatory variables. Parametric quantile regression
Inference for a quantile regression model For a parametric quantile regression, we will naturally wish to estimate the parameters, and provide confidence intervals or hypothesis tests. We will also want to visualise the fitted line Just is in ordinary linear regression, these can be done for a simple quantile regression, using the summary and abline commands in the quantreg package. Diagnostics- unlike ordinary linear regression, there is less emphasis on diagnostics, such as residual plots but
Inference for a quantile regression model Quite commonly we would fit and plot linear models for a series of quantiles and visually examine how whether they are parallel, fan out or even cross. Fanning out might indicate that the variance is not constant. Confidence intervals for the slope and intercept can be calculated (but is a challenge) and they too are commonly presented as a function of the quantile .
Linear regression quantile Inference plots for a simple linear quantile regression (from Caren Marzban presentation downloaded Dec 2013)
This time the model includes smooth terms rather than a parametric function Qlog(flow)(0.99|x) = s1(time) + s2(day of year) + s3(time,day of year) + This model was used to model the high quantiles (so extreme) river flow The data were daily, so that flow is considered to depend on a trend, s1 , when within the year (a seasonal component), s2 an interaction, s3 Non-parametric quantile regression
Quantile regression in R Within R, the quantreg package, fits regression models to any quantile fit1 <- rq(y ~ x, tau = 0.5, data = ???) Tau is the quantile (in this case the 50th so a median regression)
Additive quantile regression in R Fitting additive models for the quantiles is more complex, but can be done in the quantreg package, using rqss fit1 <- rqss(y ~ x1 +qss(x2 , lambda=3), tau = 0.5, data = ???) Tau is the quantile (in this case the 50th so a median regression) qss indicates that x2 will appear in a smooth fashion, lambda is the smoothing parameters. These methods are very data hungry!!!
Case studies The environmental examples we will examine include species density, daily river flow, and also maximum daily temperature for 30 years for the city of Twente in the Netherlands (downloaded from the Dutch meteorological organisation). There is a separate handout and a scriptfile quantcase.r
References • Cade B, Noon B. (2003). A gentle introduction ro quantile regression for ecologists. Front Ecol Environ 1(8) 412-420 • Koenker R,. (2003). Quantile regression in R: A vignette. Ecology 84(8), 2034-2041. • Also web pages of R Koenker give some further examples of the use of QR in ecology.