我对 R 还很陌生。 我从许多参考文献中收集了有关昆虫寄生虫感染的数据,其中它遵循 3 个参数逻辑函数,其中 x = 寄生虫计数(浓度),y = 受感染昆虫的比例(由不同数量的受感染昆虫/总解剖数量组成)。
我是否有可能得到由不同解剖总数加权的方程(解剖昆虫越多,结果就越可靠和重要)?
比如在 R 中使用 optim、lme 或 lmne 包?
我的数据如下所示:
> dat <- read_excel('Data.xlsx') %>%
+ # view() %>%
+ glimpse()
Rows: 158
Columns: 15
$ Reference <chr> "(Bryan & Southgate, 1988…
$ Parasite_count_per_1uL <dbl> 0.9313223, 1.0464999, 1.1…
$ Insect_totaldissected <dbl> 30, 50, 20, 36, 32, 40, 3…
$ Insect_infected_count <dbl> 1, 4, 3, 7, 3, 6, 2…
$ Insect_larvae_infected_proportion_fromtotaldissected <dbl> etc...
I did tried nlme but I don't want to group the parasite count, it will make such a huge data loss in details. What I want to do is create a model (get the 3 parameters based on the data fitting) and weight it based on Insect_totaldissected.
library(nlme)
# 3 params model are choosen based on visual interpretations by using SSlogis()
model_sslogis <- nls(Insect_larvae_infected_proportion_fromtotaldissected ~ SSlogis(Parasite_count_per_1uL, A, B, C),
data = dat,
algorithm = "port",
# weights = 1/sd_Insect_larvae_infected
)
summary(model_sslogis)
您可以对计数进行建模,而不是对比例进行建模:
total <- 30:50
parasite <- rgamma(20, 1, 1)
probs <- SSlogis(parasite, Asym = 0.8, xmid = 1, scal = 0.1)
count <- rbinom(20, total, probs)
library(bbmle)
LL <- function(Asym, xmid, scal) {
-sum(dbinom(count, size = total, prob = SSlogis(parasite, Asym, xmid, scal), log = TRUE))
}
mle2(
LL, method="L-BFGS-B",
lower = c(Asym = 0, xmid = -Inf, scal = 0.01),
upper = c(Asym = 1, xmid = Inf, scal = Inf),
start = list(Asym = 0.5, xmid = 1, scal = 0.1)
)