Victor Tello Mercado
2023-09-07
knitr::opts_chunk$set(echo = T, comment=" ", message=F, warning=F,options(scipen=999, root.dir = "D:/MANEJO FITOSANITARIO 2023/R_para_SEMINARIOS"))
#install.packages("ecotox")
library(ecotox)
#install.packages("openxlsx")
library(openxlsx)
#install.packages("ggplot2")
library(ggplot2)
#install.packages("dplyr")
library(dplyr)##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#install.packages("knitr")
library(knitr)
#install.packages("DT")
library(DT)
#install.packages("gridExtra")
library(gridExtra)##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
lc_ext <- subset(df, application %in% c("extracto"))
p1 <- ggplot(data = lc_ext[lc_ext$nominal_dose != 0, ],
aes(x = log10(dose), y = (response / total))) +
geom_point() + ggtitle("Gráfico Dosis-Probit (Extracto Botánico)")
geom_smooth(method = "glm",
method.args = list(family = binomial(link = "probit")),
aes(weight = total), colour = "#FF0000", se = TRUE) mapping: weight = ~total
geom_smooth: na.rm = FALSE, orientation = NA, se = TRUE
stat_smooth: na.rm = FALSE, orientation = NA, se = TRUE, method.args = list(family = list(family = "binomial", link = "probit", linkfun = function (mu)
qnorm(mu), linkinv = function (eta)
{
thresh <- -qnorm(.Machine$double.eps)
eta <- pmin(pmax(eta, -thresh), thresh)
pnorm(eta)
}, variance = function (mu)
mu * (1 - mu), dev.resids = function (y, mu, wt)
.Call(C_binomial_dev_resids, y, mu, wt), aic = function (y, n, mu, wt, dev)
{
m <- if (any(n > 1))
n
else wt
-2 * sum(ifelse(m > 0, (wt/m), 0) * dbinom(round(m * y), round(m), mu, log = TRUE))
}, mu.eta = function (eta)
pmax(dnorm(eta), .Machine$double.eps), initialize = {
if (NCOL(y) == 1) {
if (is.factor(y))
y <- y != levels(y)[1]
n <- rep.int(1, nobs)
y[weights == 0] <- 0
if (any(y < 0 | y > 1))
stop("y values must be 0 <= y <= 1")
mustart <- (weights * y + 0.5)/(weights + 1)
m <- weights * y
if ("binomial" == "binomial" && any(abs(m - round(m)) > 0.001))
warning(gettextf("non-integer #successes in a %s glm!", "binomial"), domain = NA)
}
else if (NCOL(y) == 2) {
if ("binomial" == "binomial" && any(abs(y - round(y)) > 0.001))
warning(gettextf("non-integer counts in a %s glm!", "binomial"), domain = NA)
n <- (y1 <- y[, 1]) + y[, 2]
y <- y1/n
if (any(n0 <- n == 0))
y[n0] <- 0
weights <- weights * n
mustart <- (n * y + 0.5)/(n + 1)
}
else stop(gettextf("for the '%s' family, y must be a vector of 0 and 1's\nor a 2 column matrix where col 1 is no. successes and col 2 is no. failures", "binomial"), domain = NA)
}, validmu = function (mu)
all(is.finite(mu)) && all(mu > 0 & mu < 1), valideta = function (eta)
TRUE, simulate = function (object, nsim)
{
ftd <- fitted(object)
n <- length(ftd)
ntot <- n * nsim
wts <- object$prior.weights
if (any(wts%%1 != 0))
stop("cannot simulate from non-integer prior.weights")
if (!is.null(m <- object$model)) {
y <- model.response(m)
if (is.factor(y)) {
yy <- factor(1 + rbinom(ntot, size = 1, prob = ftd), labels = levels(y))
split(yy, rep(seq_len(nsim), each = n))
}
else if (is.matrix(y) && ncol(y) == 2) {
yy <- vector("list", nsim)
for (i in seq_len(nsim)) {
Y <- rbinom(n, size = wts, prob = ftd)
YY <- cbind(Y, wts - Y)
colnames(YY) <- colnames(y)
yy[[i]] <- YY
}
yy
}
else rbinom(ntot, size = wts, prob = ftd)/wts
}
else rbinom(ntot, size = wts, prob = ftd)/wts
}, dispersion = 1)), method = glm
position_identity
-Uso de glm() para determinar los valores de CL usando el modelo probit para “neem” y “huacatay”
par(mfrow = c(1, 2))
n <- ggplot(data = lc_neem[lc_neem$nominal_dose != 0, ],
aes(x = log10(dose), y = (response / total))) +
geom_point() + ggtitle("Gráfico Dosis-Probit (Neem)") +
geom_smooth(method = "glm",
method.args = list(family = binomial(link = "probit")),
aes(weight = total), colour = "#FF0000", se = TRUE)h <- ggplot(data = lc_huacatay[lc_huacatay$nominal_dose != 0, ],
aes(x = log10(dose), y = (response / total))) +
geom_point() + ggtitle("Gráfico Dosis-Probit (Huacatay)") +
geom_smooth(method = "glm",
method.args = list(family = binomial(link = "probit")),
aes(weight = total), colour = "#FF0000", se = TRUE)