[R] GLM FITTED VALUES TABLE

Bill.Venables@csiro.au Bill.Venables at csiro.au
Sat Nov 29 08:11:29 CET 2003


Converting a collection of factors and a vector into an array is a general
problem for which there is no general tool available (but it would be easy
to write and curiously the S-PLUS function as.data.frame.array  does the
inverse operation).  Let me think about it...

In your case, however, the operation is easy, because you can exploit the
regular layout of the data.

not <- c("none", "one", "two")
dm <- rep(3,3)
dn <- list(c = not, f = not, t = not)
Otable <- array(allergy$y, dim=dm, dimnames = dn)
Etable <- array(fitted(allergy.fit.main.2int), dim = dm, dimnames = dn)
Etable

You just need to remember that the dimensions come out as c-rows, f-colums,
t-layers.  If you want them in some other order the tool to use is aperm( ),
but I'll leave that interesting story for you to sort out.

Bill Venables.



: -----Original Message-----
: From: allan clark [mailto:allan at stats.uct.ac.za] 
: Sent: Friday, 28 November 2003 11:02 PM
: To: r-help at stat.math.ethz.ch
: Subject: [R] GLM FITTED VALUES TABLE
: 
: 
: 
:    Hi all
: 
:    I have the following generalized linear problem.
: 
:    In a study of allergic responses, patients arriving at a clinic in
:    Groote Schuur hospital were tested for sensitivity to a number of
:    substances. Three of these were moulds: Cladosporium (C), 
: Alternaria
:    (F) and Aspergillius (T). Their level of sensitivity was 
: measured on
:    the Rast Scale as: 0: not allergic   1: mildly allergic   
: 2 or more:
:    allergic
: 
:    The data is supplied below. The analysis is fairly straight forward
:    and I understand how R solves the problem. I've supplied a 
: copy of the
:    code in order to perform the analysis.
: 
:    My question is: HOW DOES ONE CONVERT THE OUTPUT (FITTED VALUES)
:    SUPPLIED BY R AND DISPLAY THEM IN A CONTINGENCY TABLE?
: 
:    allergy<-read.table("c:/a.dat",header=T)
:    attach(allergy)
:    allergy.fit.main.2int<-glm(y~ .^2,family=poisson, data=allergy)
:    
: 
:    The fitted values are:
:            1          2          3          4          5
:    6          7          8
:    666.198041  25.858478  14.943481  60.568127   5.350317   5.081557
:    28.233832   3.791205
:             9         10         11         12         13
:    14         15         16
:     10.974962  32.170233   7.068334   1.761433  14.077680   7.039304
:    2.883016   7.752087
:            17         18         19         20         21
:    22         23         24
:      5.892362   7.355551  35.631726  14.073188  14.295086   7.354193
:    6.610380  11.035427
:            25         26         27
:      9.014081  12.316433  62.669487
: 
:    The data for those interested is as follows:
: 
:    > allergy
:          t    f    c   y
:    1  none none none 671
:    2  none none  one  23
:    3  none none  two  13
:    4  none  one none  60
:    5  none  one  one   8
:    6  none  one  two   3
:    7  none  two none  24
:    8  none  two  one   4
:    9  none  two  two  15
:    10  one none none  31
:    11  one none  one   9
:    12  one none  two   1
:    13  one  one none  14
:    14  one  one  one   6
:    15  one  one  two   4
:    16  one  two none   9
:    17  one  two  one   5
:    18  one  two  two   7
:    19  two none none  32
:    20  two none  one  15
:    21  two none  two  17
:    22  two  one none   8
:    23  two  one  one   5
:    24  two  one  two  12
:    25  two  two none  12
:    26  two  two  one  13
:    27  two  two  two  59
: 
:    Regards
:    Allan
: ______________________________________________
: R-help at stat.math.ethz.ch mailing list
: https://www.stat.math.ethz.ch/mailman/listinfo/r-help
:




More information about the R-help mailing list