11.07.2015 Views

statisticalrethinkin..

statisticalrethinkin..

statisticalrethinkin..

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12.1. ORDERED CATEGORICAL OUTCOMES 305value corresponding to each is just the cumulative log-odds of each. So you can computethem directly from these proportions, just by using the formula for log-odds. For example,the log-odds for “2” must be:ϕ 2 = log0.81 − 0.8 ≈ 1.39.at is what I mean when I say that each ϕ k value translates between the probability andlog-odds scales. If you know one, you can compute the other.But we need a way to allow the distribution to change, as a result of predictor variables.is is where the generalized linear model comes back. ink of the example just aboveas a GLM in which there are only intercepts, no predictor variables. is is akin to a linearregression with only a single parameter, α, in the model of µ i . In this case, however, therehas to be a unique intercept for each observable value (1, 2 or 3, in the example). Otherwise,the distribution wouldn’t be sufficiently flexible. Recall, we’re resorting to this orderedcategorical density, because we don’t have any basis to say that the “distance” between eachobservable value is the same. All these unique intercepts do is take an arbitrary cumulativeprobability density and translate it to cumulative log-odds.So how do we get predictor variables and β coefficients back in here? Just add them toϕ k . But while there still needs to be a unique intercept for each observable value k, the restof the additive model will be common to all values ϕ k . In effect, this means pulling out aunique intercept parameter for each observable value, and then adding a common additivemodel to each. So now the cumulative log-odds of any value k will be defined as:logPr(y i ≤ k)1 − Pr(y i ≤ k) = α k + ϕ i .In turn, ϕ i is an additive model that may contain slope parameters and predictor variables.It’s functionally just like µ i , from all of those Gaussian models you fit in earlier chapters.What these assumptions do is allow the distribution of observable values to vary as aconsequence of the predictor variables inside ϕ i . is will make more sense, once you fitone of these models and plot its implied predictions. I’ll walk you through that. But first,we need to actually code the density function that will make estimating the naive posteriorpossible.Overthinking: Coding the ordered logistic density. A density function is a block of code that takesobserved values and parameters as inputs and returns likelihood (or log-likelihood) correspondingto those inputs. ere’s nothing stopping you from writing your own density functions. en you canuse them in map and in other calculations. e density function we need to perform ordered logisticregression, dordlogit, is already in the rethinking package. But this is a good spot to provide aglimpse at how R actually uses density functions to fit models. Here, we’ll write our first completelycustom density function.You do, however, have to obey a small number of conventions, in writing a density function.First, the first parameter must be a vector of values to compute likelihoods for, and this vector must benamed x, just because R expects it to have this name. Second, there must be a parameter named log,and when it is set to TRUE, the function should return log-likelihood, rather than ordinary likelihood.Ideally, the function will return one (log-)likelihood for each element of the input x. Other parametersdefined in the function are for the parameters of the likelihood function, the µ’s and σ’s and such. Youcan name those whatever you want.Let’s write the density function for the ordered categorical distribution. is function is alreadybuilt into the rethinking package, but it’s worth examining it, as an example of how build your own

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!