I have a table with Ancylostoma's infection, vs sex (2 factor), location (2 factor), year, management (2 factor), ancestry (4 factor) and viremia like categorical variable, and the I have HL an age like numeric variable.**
I made a glmm:
glm_toxo<-glmer((Ancylostoma) ~ as.factor(Sexo)+(Edad)+as.factor(año)+as.factor(Manejo)+as.factor(Localizacion)+as.factor(Viremia.FeLV) +(Ancestria) +(HL)+as.factor(1|Nombre), family="binomial", data= data_silv)
dd_toxo <- dredge (glm_toxo)
a<- get.models(dd_toxo, subset = delta < 2)
b<-(model.avg(a))
And I got this result
Model-averaged coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.0222 0.8911 2.269 0.0233 *
as.factor(Localizacion)PORT -15.2935 2163.9182 0.007 0.9944
as.factor(Localizacion)SMO -3.0012 0.7606 3.946 7.95e-05 ***
as.factor(Manejo)SILV 1.8125 0.7799 2.324 0.0201 *
Edad -0.1965 0.1032 1.904 0.0569 .
as.factor(Sexo)M 0.5015 0.4681 1.071 0.2840
HL -0.9381 1.4244 0.659 0.5102
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
I would like represent the probability of infection (y) vs age (x), but using the estimate of my model.avg**
I tried with this script:
nseq <- function(x, len = length(x)) seq(min(x, na.rm = TRUE),max(x, na.rm=TRUE), length = len)
####
newdata <- as.data.frame(lapply(lapply(data_silv[2:4], mean), rep, 213))
newdata$Edad <- nseq(data_silv$Edad, nrow(newdata))
(año <- sample(as.factor(data_silv$año),size=213,rep=T))
(Manejo <- sample(as.factor(data_silv$Manejo),size=213,rep=T))
(Sexo <- sample(as.factor(data_silv$Sexo),size=213,rep=T))
newdata <- as.data.frame(cbind(mean(data_silv$HL), año,Manejo,Sexo,
data_silv$Localizacion, nseq(data_silv$Edad, nrow(newdata)),
data_silv$Ancylostoma))
names(newdata) <- c("HL","año","Manejo","Sexo","Localizacion","Edad",
"Ancylostoma")
newdata$pred <- data.frame(
model = sapply(a, predict, newdata = newdata),
averaged.subset = predict(b, newdata, full = FALSE),
averaged.full = predict(b, newdata, full = TRUE)
)
library(ggplot2)
ggplot(newdata,aes(x="Edad",y="pred",color="Localizacion")) + geom_line()
#####
But I haven't got graph...or I have error
Someone know any form to represent my model.avg with categorical and variable numeric?, But taking into account that I only want represent probability of infection vs age, with two line: localizacion1 and localizacion2...(localization had 2 factors).**
my original date would be this table:
#
año <- sample(as.factor(2005:2009),size=213,rep=T)
riqueza <- sample((0:3),size=213,rep=T)
HL <- rnorm(213, mean=0.54, sd=0.13)
Ancylostoma <- sample(as.factor(0:1),size=213,rep=T)
Edad <- sample(as.factor(0:21),size=213,rep=T)
Manejo<- sample(c("CCC", "SILV"), 213, replace = TRUE)
Sexo<- sample(c("M", "H"), 213, replace = TRUE)
Localizacion<- sample(c("SMO", "DON", "PORT"), 213, replace = TRUE)
Ancestria<- sample(c("DON", "SMO", "F1", "F2"), 213, replace = TRUE)
newdata <- as.data.frame(cbind(HL,año,Manejo,Sexo,
Localizacion, Edad,Ancylostoma))
names(newdata) <- c("HL","año","Manejo","Sexo","Localizacion","Edad",
"Ancylostoma")
#
And with that date I make my model's estimates. Then I would like do prediction
Thank you, I don't sure if I am explaining well
I so sorry for my english