# Logistic regression for learning curve analysis - two trends

I had 10 animals repeatedly performing a two-alternative forced choice task (choosing between two coloured stimuli to get a reward). The outcome was either success or fail. Once the success rate of the animals reached a certain criterion, I altered the brightness of one of the stimuli to see if the success rate would decrease again, so I could see what their learning depended on.

I am working in R and I think I have to do logistic regression on this dataset, with success/fail as dependent variable and trial number as independent variable (to show improvement over time). I am trying this with the glm function. I had some basic statistics training, but I have some questions about this that I can't figure out myself.

1. In the beginning, I suspect the animals have a 50/50 success/fail ratio. Can I do logistic regression when the chance of success ranegs from 50% to 100%, instead of 0% to 100% (which I see in all examples)?
2. If so, how can I take this into account in my logistic regression? I read something about changing the cut-value to match the abundance of the two outcomes, should I do that?
3. I want to see if I have one overall trend, or two separate trends in my dataset: from start until the changed stimulus, and from changed stimulus until the end. I've now created two subsets of the dataset. Is that the way to go, or am I forgetting something?
4. How do I take into account other independent variables in logistic regression in R, like the colour, brightness and side of the stimulus? And the differences between the animals?
5. Finally, how can I visualise the logistic regression well in R (or another way to display the learning curve)?

I didn't find answers to these questions on the forum, but if I overlooked them I apologise! Any help at all would be appreciated, as I don't have anyone around atm who can help me with this.

• Hello and welcome on CrossValidated. So I understand that in the first phase you'll want to know how fast an animals learns and you will compute success ~ number of trial. Then you change the brigthness. After that, are you still interested in learning rate over trys or only in one fixed "rate after brightness change"? Are you aware of random effects as a possibility to include each animals personal learning abilities? Jan 21 at 12:11
• Hi Bernhard! Thank you for your reply! Yes, that's correct. After the brightness change, I am still interested in the learning curve. I would like to see if their learning curve continues after the change, stagnates or 'breaks down', as this would answer my main question. Someone did tell me about random effects and I've researched it a bit, but I don't know how to apply this to my example
– Amy
Jan 21 at 13:29
• Edit: actually, not necessarily how fast the animals learn but rather if they are learning at all
– Amy
Jan 21 at 13:36

my answer will not be specific to R but I think you can find the way of doing this by looking elsewhere.

UPDATE: you say you just want to see if they learn at all. Then you don't need to use $$k$$, but check if $$r_0 \neq r_\inf$$. For this actually, you don't need to fit a logistic. I think a simpler approach should suffice. In the end, the best way would be to have many different values of $$r_0$$ and $$r_\inf$$ and then use hypothesis testing to assert whether their averages differ or not.

Points 1 & 2

Let's call your learning rate $$r$$ and the trial number $$n$$. A general logistic curve is

$$r(n)=\frac{a}{b+e^{-k(n-n_0)}}$$

where $$n_0$$ is the number you use for the first trial. Let's call the first trial $$n_0=0$$ since that will simplify the maths. Now, you calculate your empirical success rates $$r$$ and fit them versus the trial number (starting with trial #0), from where you get the values of $$a$$, $$b$$, and $$k$$. That curve does not make any assumptions about the initial learning rate, or even the final learning rate

Now we can interpret the parameters in terms of what you want. You start with a pure-chance success rate of $$r_0$$ for $$n=0$$. Also, when $$n$$ tends to infinity, the rate will be $$r_\inf$$. Substituting those conditions in the logistic, we have

$$r_0 = \frac{a}{b+1}$$ $$r_\inf = \frac{a}{b}$$

If you substitute there the parameters you obtained from the fit, you will see if the initial learning rate is $$r_0=0.5$$, and which is the maximum rate reached after a lot of training, $$r_\inf$$. The learning rate is characterized by the parameter $$k$$, which you also get from the fit.

Point 3

I don't fully understand. Do you want to see if different animals learn faster? What you can do is make a fit for each animal, from where you will get different values of $$k$$, and then compare those values. However, depending on your data, the results might not be statistically conclusive about the existence of different values of $$k$$, and they might all be the same but the noise makes them look different.

Point 4

Maybe you can repeat the analysis for each different experiment setup, and then compare the values of $$r_0$$, $$r_\inf$$ and $$k$$ and see if there is a relation between e.g. color and maximum learning by plotting $$r_\inf$$ vs color etc. You can compare everything against everything and find possible correlations.

Point 5

I don't know the commands in R, but once you have $$a$$, $$b$$ and $$k$$ you can plot $$r$$ vs $$n$$, and if you plot the data points in the sample plot you will see if your data is well described by that logistic (the first thing to do!). Afterward, you can do as I said in the previous point and plot parameters vs parameters as a summary.