Kyle
Kyle

Reputation: 725

Fitting a Logistic Curve, obtain parameters for each record

I'm attempting to fit a simple logistic curve, 1 response ~ 1 predictor.

library("drc")
mL <- drm(percent_farm_tractor ~ year, data = final.df, fct = L.3(), 
type = "continuous")
summary(mL)
plot(mL)
coef(mL)
modelFit(mL)

I'm used to using logistic regression as a classification method and the use of these packages is pretty unknown to me. This model returns the summary and fit plot below:

Model Summary

Model Summary

Plot

Model Plot

I understand "b" to be the slope, "d" to be the ceiling, and "e" to be the inflection point. To give some context I am looking at number a tractors in each county on a given year and expect this to follow the S-curve. So I am looking for these 3 parameters but for each county in my dataset.

Upvotes: 0

Views: 439

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226692

Something like:

library(drc)

Split the data frame into a list of data frames, one per county:

split_df <- split(final.df, final.df$county)

A function to fit the model to a data set and return the coefficients:

fitfun <- function(d) {
    mL <- drm(percent_farm_tractor ~ year, data = d, fct = L.3(), type = "continuous")
    return(coef(mL))
}

Apply the function to each chunk of the data:

lapply(split_df, fitfun)

Upvotes: 1

Related Questions