serenity-r / serenity

Data science in the classroom. To read more about the vision for Serenity: https://doi.org/10.6084/m9.figshare.5483692.v3
1 stars 1 forks source link

Fit nonlinear models in Serenity? #1

Open nemery1 opened 6 years ago

nemery1 commented 6 years ago

Hi!

I have my 200 student Intro Bio course using Serenity for modeling plant phenology data they collected and they're chomping at the bit. They just learned about exponential and logistic models of population growth and really want to fit non-linear equations to their scatterplots.

Is there any way to fit more than just a basic line? perhaps a polynomial equation?

Thanks! Nate

mdlama commented 6 years ago

Hi, Nate! That's great they collected their own data. Would love to catch up with you again to see how data collection went (last we chatted, they were going to use a smartphone app to do it?)

Regarding Serenity's ability to do more fancy regressions, it is pretty limited at the moment. Serenity is essentially a stripped down version of Radiant right now, so I would recommend playing with Radiant, which you can also launch on QUBES (https://qubeshub.org/tools/radiant). It's a bit more involved to do logistic and exponential regressions, but they can be done. Here's what I know:

  1. For logistic in Radiant, go to Model -> Logistic regression (GLM). The Plot tab doesn't work at the moment, but if you want a visual, you can click on Predict and use the Data for the prediction, then check the "Plot prediction" checkbox. It won't overlay the curve on the data, but it might be good enough for your interests.

  2. For exponential, you can do a linear regression on a transformed response variable to get an exponential regression for the untransformed response. To see this, if X is the explanatory and Y is the response, you have:

latex-image-1

In Radiant, first add a new variable by going to Data -> Transform, choose the response variable and choose Transform under Transformation type. You'll see natural log. Choose that and store the resulting variable back into the same dataset. You should then be able to perform linear regression on the resulting transformed response variable. If you want the parameters for the exponential, you can use the relationships in the equations above. Note that you might need to first shift the response variable so that they are all positive before taking the natural log. This has the effect of fitting an exponential with a vertical shift.

Hope that helps! Also, I'm not sure if we discussed this, but Serenity looks a lot like Radiant because I was going to start with Radiant as the base. I have since decided to go a different route and completely redesign the UI. What this means is if the new Serenity UI doesn't float your boat, you can always use Radiant! That shouldn't happen for awhile, though, so Serenity should be stable, even through the Spring semester.

nemery1 commented 6 years ago

Hi Drew,

Thanks! I have been directing them to Radiant if they want to try out statistical analysis of their data. I didn't want to pivot 200 students to a different app mid-semester (even though it's basically the same). I'll try out your suggestions and incorporate them into the protocols I build for next year. Let's chat when the semester's over about the +'s and -'s of our project with Serenity/Radiant and Ona.io (data collection). Maybe skype or a phone call?

Cheers, Nate