[R-br] Problema para plotar IC para modelo glm Gamma usando stat_smooth() no ggplot2

ASANTOS alexandre.santos em cas.ifmt.edu.br
Seg Dez 10 02:47:12 -02 2018


Prezados Membros do R-br,

     Estou tentando plotar um modelo glm Gamma com stat_smooth() no 
ggplot2 sem sucesso. Minha ideia é representar o intervalo de confiança 
para um modelo onde realizei a junção de dois níveis para o fator 
Feature. Segundo exemplo fictício do meu problema:

#Simulação de um banco de dados, onde a variável resposta Production tem 
distribuição Gamma
set.seed(123)
d<-NULL
N<-50
d$Production <- rgamma(N,10)
d$Feature <- ifelse(d$Production >7 & d$Production<10, 
c("green"),ifelse(d$Production>11,
c("red"), c("blue")))
d$Temp<-rnorm(N,20,5)
d<-as.data.frame(d)
#

# Ajusto um modelo de Gamma completo
mG<- glm(Production~ Feature + Temp, family= Gamma, data = d)
summary(mG)
anova(mG,test="Chi")

# Comparo os níveis do fator Feature
library(multcomp)
PW<-summary(glht(mG, linfct = mcp(Feature= "Tukey")))
PW
cld(PW)

# Faço de conta que os níveis green = blue e realizo um novo ajuste
Feature2<-d$Feature
levels(Feature2)
levels(Feature2)[1]<-"blue&green"
levels(Feature2)[2]<-"blue&green"
levels(Feature2)
d$Feature2<-Feature2
mG2<- glm(Production~ Feature2 + Temp, family= Gamma, data = d)

# Crio os valores de predição
pred.data = data.frame(
Feature2<-d$Feature2,
Temp<-d$Temp
)
pred.data$Production = predict(mG2, newdata=pred.data, type="response")

#Realizo o plot
library("ggplot2")
ggplot(d, aes(Temp, Production, colour = Feature2)) +
   geom_point() +
   geom_line(data=pred.data) +
   stat_smooth(method = "glm", formula = y ~ x, family = Gamma)
#

      E tenho uma representação errada do intervalo de confiança do meu 
modelo mG2 porque não consigo fazer a função stat_smooth() considerar o 
ajuste mG2. Como posso resolver isso?

Obrigado

-- 
======================================================================
Alexandre dos Santos
Proteção Florestal
IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
Campus Cáceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial
Cáceres - MT                      CEP: 78.200-000
Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 (FIXO)
e-mails:alexandresantosbr em yahoo.com.br
         alexandre.santos em cas.ifmt.edu.br
Lattes: http://lattes.cnpq.br/1360403201088680
OrcID: orcid.org/0000-0001-8232-6722   -   ResearcherID: A-5790-2016
Researchgate: www.researchgate.net/profile/Alexandre_Santos10
LinkedIn: br.linkedin.com/in/alexandre-dos-santos-87961635
Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/
======================================================================



Mais detalhes sobre a lista de discussão R-br