I'm trying to analyze some sleep data from kaggle (this example data does not have correct temperature data but the actual data I will use in the future will have precise temperature) to try to find the temperature value that gives the best sleep quality.
At first I thought of trying some linear regression between sleep quality and some of the other variables and check the coefficient for the temperature. However, I don't think this is the right way to go because the relation between the two variables is not linear (i.e. if we were to start at 0ºC the quality improves as the temperature gets higher but it does not keep improving as the temperature increases higher than 40ºC, for example). A solution I find to this is to categorize the temperature in intervals and continue with the regression this way.
What I'm wondering is if this is the right way to do this or if there is a better way to do calculations like this where the relation between the two variables is not linear. I was wondering if there are other methods I should look into.
In summary, I would like to find in a way the temperature value that gives the best sleep quality like "solving an equation" in a way or with some other method. I would really appreciate any links or references about the topic as well.