[R] producing a graph with glm poisson distributed respons count data and categorical independant variables

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Jul 27 16:44:08 CEST 2012


Dear Babs,

This is how I would present the model, if I had enough data to support the model. The model is too complicated for your data and leads to a perfect fit. Is this the aggregated dataset, or does your design has no replicates?

Best regards,

Thierry

dataset$combinatie <- dataset$proefopzet:dataset$mengsel
model <- glm(count ~ offset(log(opp)) + proefopzet * mengsel, data = dataset, family = poisson)
modelPlot <- glm(count ~ offset(log(opp)) + 0 + combinatie, data = dataset, family = poisson)
summary(model)
summary(modelPlot)
all.equal(fitted(model), fitted(modelPlot))

library(multcomp)
extra <- as.data.frame(confint(glht(modelPlot))$confint)
extra <- exp(extra)
extra$proefopzet <- factor(substr(rownames(extra), 11, 12))
extra$mengsel <- factor(substr(rownames(extra), 14, 14))
dataset <- merge(dataset, extra)

library(ggplot2)
ggplot(dataset, aes(x = mengsel, y = count / opp, ymin = lwr, ymax = upr, colour = proefopzet)) + geom_errorbar() + geom_point(shape = "O") + geom_point(aes(y = Estimate))


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx op inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey


-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org] Namens babs
Verzonden: vrijdag 27 juli 2012 15:35
Aan: r-help op r-project.org
Onderwerp: [R] producing a graph with glm poisson distributed respons count data and categorical independant variables

Hello,

I am working on my thesis and can't really figure out how to produce a
reasonable graph from the output from my glm.,
I could just give the R-output in my results and then discuss them, but it
would be more interesting if I could visualise what is going on.
My research is how bees react to different fieldmargins, for this I have 4
different types of field margin (A,B,C & D) and two different experiments,
one where the field margins are adjecent and one where they are seperated.
I wanted to know if the bees react differently on the different types of
field margin and whether there were differences between the two
experiments... I also used an offset function to correct for the different
number of field margins of the same type were the counts have been going on.
I counted the counts of the same fied margins together and then put in the
offset function.

So i used the model that is underneath: mengsel A, B, C & D=type of field
margin and proefopzet 1 and 2= experiment p1 and p2
I already checked if this saturated model is better then that without an
interaction effect:
so I think i have a good model for my data

Call:
glm(formula = count ~ mengsel * proefopzet, family = poisson,
    data = a.data, offset = log(opp))

Deviance Residuals:
[1]  0  0  0  0  0  0  0  0

Coefficients:
                      Estimate Std. Error z value Pr(>|z|)
(Intercept)            5.01507    0.04704 106.622  < 2e-16 ***
mengselB               0.82654    0.05640  14.656  < 2e-16 ***
mengselC              -1.36441    0.12329 -11.067  < 2e-16 ***
mengselD              -2.30702    0.18854 -12.237  < 2e-16 ***
proefopzetp2          -0.92909    0.10303  -9.017  < 2e-16 ***
mengselB:proefopzetp2  0.14373    0.13399   1.073 0.283411
mengselC:proefopzetp2 -2.02842    0.52307  -3.878 0.000105 ***
mengselD:proefopzetp2  3.03323    0.22821  13.291  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance:  1.8216e+03  on 7  degrees of freedom
Residual deviance: -1.2212e-14  on 0  degrees of freedom
AIC: 67.589

Number of Fisher Scoring iterations: 3

>
Now...how can i visualise this? I don't seem to find how i could do this...

The data on which this is computed is the following:
> a.data
  count proefopzet mengsel opp
1  1033        p1               B            3
2    77           p1               C             2
3   452         p1               A             3
4    30          p1               D             2
5   157         p2               B             1
6     4            p2              C             2
7   119         p2               A             2
8   123         p2               D             1

Thanks,

Babs







--
View this message in context: http://r.789695.n4.nabble.com/producing-a-graph-with-glm-poisson-distributed-respons-count-data-and-categorical-independant-variabs-tp4638110.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help op r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.


More information about the R-help mailing list