Binomial GLM in Julia - how to indicate hits and misses

In Julia, I would like to calculate GLM with the Binomial()and family LogitLink(). My data is three linear arrays:, xvaluesnumber hitsand number misses. I would like to talk about binomially distributed hits and misses on their positions along the x axis. I have several samples with the same x coordinates (because the data originally came from a 2D array that was flattened).

In R, I have to provide hits and misses in a two-column matrix. Something like the following works:

glm1 <- glm(cbind(hits, misses)~xvalues, family=binomial)

But in the GLM formula in Julia I cannot specify arbitrary arrays. Rather, I have to specify the columns from the data frame, and the dataframe columns cannot be 2D, it seems. So I put my data in a data framework:

data = DataFrame(xvals = xvals, hits = hits, misses = misses)

and tried things that don't work (like this):

glm1 = glm(hcat(hits, misses) ~ xvals, data, family = Binomial, link = LogitLink())

An example of the data can be downloaded here .

Any tips? Hooray, Hannes

+4
source share
1 answer

While it’s quite difficult to inflate a data set into a string framework of ~ 100k size, it will make it work. To use the code below, first upload your dataset to xvals, hitsand misses(as indicated in the question), and then:

# spreading dataset to one row per trial...   
data = DataFrame(
    xvals = vcat(rep(xvals,hits),rep(xvals,misses)), 
    outcome = vcat(rep(1,sum(hits)),rep(0,sum(misses))))

glm1 = glm(outcome ~ xvals, data, Binomial(),LogitLink())

The results seem to be consistent with my cursory glance. Also note that Binomialand LogicLinkare positional parameters and unnamed parameters.

+2
source

Source: https://habr.com/ru/post/1617087/


All Articles