How do I plot this logistic regression in R?

39 Views Asked by At

I'm struggling to get this to work. I can plot it in Graphpad but I'm not sure if my stats are correct there. This is my data. It is # of pupae at a given day over several days. With the varibles of Container and Site. I want the model to look at # of pupae over time by container and site.

I tried the following

# logistic regression curve
model <- drm(Pupae ~ Day, fct = L.3(), data = pupation_rates,
             curveid = Container:Site)
summary(model)
plot(model, log="", main = "Logistic function")

this returns Error in Container:Site : NA/NaN argument

I can get it to plot if I remove curveid = Container:Site but it's still looking at ALL pupae. I know it's not right but I don't know how to fix it.

1

There are 1 best solutions below

0
DaveArmstrong On

You can make a new variable that is the combination of Container and Site with paste(). Then, you can give that vector of values to curvid. To estimate separate curves, use the separate=TRUE argument. Then, you can use plot() with type="all" to plot all the different curves.

pupation_rates <- rio::import("~/Downloads/pupation_rates.xlsx")
pupation_rates <- na.omit(pupation_rates)
pupation_rates$curve_id <- paste(pupation_rates$Site, pupation_rates$Container, sep="-")
library(drc)
model <- drm(Pupae ~ Day, fct = L.3(), data = pupation_rates, 
             curveid = pupation_rates$curve_id, separate = TRUE)

plot(model, 
     log="", 
     main = "Logistic function", 
     type="all", 
     legendPos = c(2.5,1))

Created on 2024-02-19 with reprex v2.0.2