From b2ca1cb301d66bacc8efde1aa86a50653f6ec18f Mon Sep 17 00:00:00 2001 From: Eduardo Junior <edujrrib@gmail.com> Date: Tue, 21 Jun 2016 10:47:32 -0300 Subject: [PATCH] =?UTF-8?q?Cria=20chunk=20para=20gera=C3=A7=C3=A3o=20de=20?= =?UTF-8?q?valores=20utilizados=20no=20texto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/cap04_resultados-e-discussao.Rnw | 72 ++++++++++++++------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/docs/cap04_resultados-e-discussao.Rnw b/docs/cap04_resultados-e-discussao.Rnw index 43d5c27..89a3cd7 100644 --- a/docs/cap04_resultados-e-discussao.Rnw +++ b/docs/cap04_resultados-e-discussao.Rnw @@ -2307,6 +2307,44 @@ fonte("Fonte: Elaborado pelo autor.") @ +<<varspred-nematodes, include=FALSE>>= + +##------------------------------------------- +## Obtendo os efeitos aleatórios +ranefP <- ranef(m2PM)$cult[, 1] +ranefC <- mixedcmp.ranef(m2CM) +ranef.all <- rbind( + data.frame(model = "PM", ranef = ranefP), + data.frame(model = "CM", ranef = ranefC)) + +##------------------------------------------- +## Valores preditos +pred <- with( + nematodes, + expand.grid(off = seq(min(off), max(off), length.out = 20), + cult = levels(cult)) + ) +X <- model.matrix(~log(off), data = pred) + +## Pelo Poisson Mixed +aux <- predict(m2PM, newdata = pred, type = "link") +predPM <- data.frame(pred, y = exp(aux), model = "MP") +muPM <- data.frame(pred, mu = exp(X %*% fixef(m2PM)), model = "MP") + +## Pelo COM-Poisson Mixed +aux <- predict(m2CM, newdata = pred, type = "link") +predCM <- data.frame(pred, y = calc_mean_cmp(aux, phi = m2CM@coef[1]), + model = "MC") +muCM <- data.frame(pred, mu = calc_mean_cmp(X %*% m2CM@coef[-(1:2)], + phi = m2CM@coef[1]), + model = "MC") + +## Agrupa as predições +pred.all <- rbind(predPM, predCM) +mu.all <- rbind(muPM, muCM) + +@ + Conforme já observado anteriormente, no modelo COM-Poisson misto os parâmetros $\phi$, da distribuição considerada para a variável de contagem condicional aos efeitos aleatórios e as covariáveis e $\sigma$, @@ -2338,14 +2376,6 @@ levam ao mesmo resultado. <<pred-nematodes, fig.height=4.2, fig.width=7.4, fig.cap="Perfis de verossimilhança dos parâmetros estimados no modelo COM-Poisson Misto.">>= -##------------------------------------------- -## Obtendo os efeitos aleatórios -ranefP <- ranef(m2PM)$cult[, 1] -ranefC <- mixedcmp.ranef(m2CM) -ranef.all <- rbind( - data.frame(model = "PM", ranef = ranefP), - data.frame(model = "CM", ranef = ranefC)) - xy1 <- densityplot( ~ranef, groups = model, auto.key = list( @@ -2358,32 +2388,6 @@ xy1 <- densityplot( grid = TRUE, par.settings = ps.sub) -##------------------------------------------- -## Valores preditos -pred <- with( - nematodes, - expand.grid(off = seq(min(off), max(off), length.out = 20), - cult = levels(cult)) - ) -X <- model.matrix(~log(off), data = pred) - -## Pelo Poisson Mixed -aux <- predict(m2PM, newdata = pred, type = "link") -predPM <- data.frame(pred, y = exp(aux), model = "MP") -muPM <- data.frame(pred, mu = exp(X %*% fixef(m2PM)), model = "MP") - -## Pelo COM-Poisson Mixed -aux <- predict(m2CM, newdata = pred, type = "link") -predCM <- data.frame(pred, y = calc_mean_cmp(aux, phi = m2CM@coef[1]), - model = "MC") -muCM <- data.frame(pred, mu = calc_mean_cmp(X %*% m2CM@coef[-(1:2)], - phi = m2CM@coef[1]), - model = "MC") - -## Agrupa as predições -pred.all <- rbind(predPM, predCM) -mu.all <- rbind(muPM, muCM) - key <- list( column = 1, lines = list(lty = c(1, 2), lwd = c(3, 1)), -- GitLab