Re: [R] Fixed zeros in tables

2006-11-27 Thread David Duffy
A.R. Criswell [EMAIL PROTECTED] wrote:

 Hello Andrew Robinson and R-List
 
 Thanks, Andrew, but this does not work. Puttting zero weights on
 structural zeros, one's elsewhere in glm() does not deliver the
 appropriate expected cell counts loglm() provides as one would expect.
 
 If you run the code provided below, you'll see loglm() delivers zero
 cell counts with loglm() but using glm() with the weights you suggest,
 the expected cell counts are not zero.
 
 Still hoping for a resolution.
 Andrew Criswell
 
 Associate Professor
 Hedmark University
 Postboks 104, Rena 2510, NORWAY

If they are structural zeros, I believe you want:

  glm(COUNT ~  CONCERNS + AGE + GENDER, data=health, subset=(WEIGHTS0),
  family=poisson)

David Duffy.

-- 
| David Duffy (MBBS PhD) ,-_|\
| email: [EMAIL PROTECTED]  ph: INT+61+7+3362-0217 fax: -0101  / *
| Epidemiology Unit, Queensland Institute of Medical Research   \_,-._/
| 300 Herston Rd, Brisbane, Queensland 4029, Australia  GPG 4D0B994A v

__
R-help@stat.math.ethz.ch 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.


Re: [R] Fixed zeros in tables

2006-11-26 Thread A.R. Criswell
Hello Andrew Robinson and R-List

Thanks, Andrew, but this does not work. Puttting zero weights on
structural zeros, one's elsewhere in glm() does not deliver the
appropriate expected cell counts loglm() provides as one would expect.

If you run the code provided below, you'll see loglm() delivers zero
cell counts with loglm() but using glm() with the weights you suggest,
the expected cell counts are not zero.

Still hoping for a resolution.
Andrew Criswell

Associate Professor
Hedmark University
Postboks 104, Rena 2510, NORWAY

--
## Fienberg, The Analysis of Cross-Classified Contingency Tables, 2nd
ed., p.148.
## Results from survey of teenagers regarding their health concerns.

health - data.frame(expand.grid(CONCERNS = c(sex, menstral,
  healthy, nothing),
 AGE  = c(12-15, 16-17),
 GENDER   = c(male, female)),
 COUNT= c(4, 0, 42, 57, 2, 0, 7, 20,
  9, 4, 19, 71, 7, 8, 10, 21),
 WEIGHTS  = c(1, 0, 1, 1, 1, 0, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1))

health.tbl - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = health)

zeros - data.frame(expand.grid(CONCERNS = c(sex, menstral,
  healthy, nothing),
AGE  = c(12-15, 16-17),
GENDER   = c(male, female)),
COUNT= c(1, 0, 1, 1, 1, 0, 1, 1,
 1, 1, 1, 1, 1, 1, 1, 1))

zeros - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = zeros)

library(MASS)

fm.1 - loglm(~ CONCERNS + AGE + GENDER,
  data = health.tbl, start = zeros, fitted = TRUE)

fm.1; round(fm.1$fitted, 1)

fm.3 - glm(COUNT ~ CONCERNS + AGE + GENDER,
  data = health, weights = health$WEIGHTS, family = poisson)

fm.3.fit - data.frame(expand.grid(CONCERNS = c(sex, menstral,
healthy, nothing),
   AGE  = c(12-15, 16-17),
   GENDER   = c(male, female)),
   COUNT= fm.3$fitted)

round(xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = fm.3.fit), 1)

__
R-help@stat.math.ethz.ch 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.


Re: [R] Fixed zeros in tables

2006-11-26 Thread Andrew Robinson
Hello Andrew,

I'm not sure how this is a problem.  You can multiply the fitted
values by the weights again, if you wish, or ignore the structural
zeros altogether.  The other predicted values all seem to me to be the
same.

I think that is a feature.  Sometimes the goal for glm with structural
zeros is to estimate those values that are missing.  You are at
liberty to ignore them.

Cheers

Andrew

On Mon, Nov 27, 2006 at 02:47:01AM +0700, A.R. Criswell wrote:
 Hello Andrew Robinson and R-List
 
 Thanks, Andrew, but this does not work. Puttting zero weights on
 structural zeros, one's elsewhere in glm() does not deliver the
 appropriate expected cell counts loglm() provides as one would expect.
 
 If you run the code provided below, you'll see loglm() delivers zero
 cell counts with loglm() but using glm() with the weights you suggest,
 the expected cell counts are not zero.
 
 Still hoping for a resolution.
 Andrew Criswell
 
 Associate Professor
 Hedmark University
 Postboks 104, Rena 2510, NORWAY
 
 --
 ## Fienberg, The Analysis of Cross-Classified Contingency Tables, 2nd
 ed., p.148.
 ## Results from survey of teenagers regarding their health concerns.
 
 health - data.frame(expand.grid(CONCERNS = c(sex, menstral,
  healthy, nothing),
 AGE  = c(12-15, 16-17),
 GENDER   = c(male, female)),
 COUNT= c(4, 0, 42, 57, 2, 0, 7, 20,
  9, 4, 19, 71, 7, 8, 10, 21),
 WEIGHTS  = c(1, 0, 1, 1, 1, 0, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1))
 
 health.tbl - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = health)
 
 zeros - data.frame(expand.grid(CONCERNS = c(sex, menstral,
  healthy, nothing),
AGE  = c(12-15, 16-17),
GENDER   = c(male, female)),
COUNT= c(1, 0, 1, 1, 1, 0, 1, 1,
 1, 1, 1, 1, 1, 1, 1, 1))
 
 zeros - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = zeros)
 
 library(MASS)
 
 fm.1 - loglm(~ CONCERNS + AGE + GENDER,
  data = health.tbl, start = zeros, fitted = TRUE)
 
 fm.1; round(fm.1$fitted, 1)
 
 fm.3 - glm(COUNT ~ CONCERNS + AGE + GENDER,
  data = health, weights = health$WEIGHTS, family = poisson)
 
 fm.3.fit - data.frame(expand.grid(CONCERNS = c(sex, menstral,
healthy, nothing),
   AGE  = c(12-15, 16-17),
   GENDER   = c(male, female)),
   COUNT= fm.3$fitted)
 
 round(xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = fm.3.fit), 1)

-- 
Andrew Robinson  
Department of Mathematics and StatisticsTel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/

__
R-help@stat.math.ethz.ch 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.


[R] Fixed zeros in tables

2006-11-25 Thread A.R. Criswell
Hello All R Users,

Function loglm() in library MASS can be cajoled to accomodate
structural zeros in a cross-classification table. An example from
Fienberg demonstrates how this can be done.

My question is: Can the function glm() perform the same task? Can
glm() estimate a log-linear model with fixed zeros like loglm()?

Thanks for your help,
Andrew

## Fienberg, The Analysis of Cross-Classified Contingency Tables, 2nd
ed., p.148.
## Results from survey of teenagers regarding their health concerns.

health - data.frame(expand.grid(CONCERNS = c(sex, menstral,
  healthy, nothing),
 AGE  = c(12-15, 16-17),
 GENDER   = c(male, female)),
 COUNT= c(4, 0, 42, 57, 2, 0, 7, 20,
  9, 4, 19, 71, 7, 8, 10, 21))

health - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = health)

zeros - data.frame(expand.grid(CONCERNS = c(sex, menstral,
  healthy, nothing),
AGE  = c(12-15, 16-17),
GENDER   = c(male, female)),
COUNT= c(1, 0, 1, 1, 1, 0, 1, 1,
 1, 1, 1, 1, 1, 1, 1, 1))

zeros - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = zeros)

library(MASS)

fm.1 - loglm(~ CONCERNS + AGE + GENDER,
  data = health, start = zeros, fitted = TRUE)

fm.1; round(fm.1$fitted, 1)

__
R-help@stat.math.ethz.ch 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.


Re: [R] Fixed zeros in tables

2006-11-25 Thread Andrew Robinson
Hi Andrew,

try the weights argument - apply zero weight to the structural zeros,
and 1 elsewhere.

Cheers

Andrew

On Sun, Nov 26, 2006 at 11:39:39AM +0700, A.R. Criswell wrote:
 Hello All R Users,
 
 Function loglm() in library MASS can be cajoled to accomodate
 structural zeros in a cross-classification table. An example from
 Fienberg demonstrates how this can be done.
 
 My question is: Can the function glm() perform the same task? Can
 glm() estimate a log-linear model with fixed zeros like loglm()?
 
 Thanks for your help,
 Andrew
 
 ## Fienberg, The Analysis of Cross-Classified Contingency Tables, 2nd
 ed., p.148.
 ## Results from survey of teenagers regarding their health concerns.
 
 health - data.frame(expand.grid(CONCERNS = c(sex, menstral,
   healthy, nothing),
  AGE  = c(12-15, 16-17),
  GENDER   = c(male, female)),
  COUNT= c(4, 0, 42, 57, 2, 0, 7, 20,
   9, 4, 19, 71, 7, 8, 10, 21))
 
 health - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = health)
 
 zeros - data.frame(expand.grid(CONCERNS = c(sex, menstral,
   healthy, nothing),
 AGE  = c(12-15, 16-17),
 GENDER   = c(male, female)),
 COUNT= c(1, 0, 1, 1, 1, 0, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1))
 
 zeros - xtabs(COUNT ~ CONCERNS + AGE + GENDER, data = zeros)
 
 library(MASS)
 
 fm.1 - loglm(~ CONCERNS + AGE + GENDER,
   data = health, start = zeros, fitted = TRUE)
 
 fm.1; round(fm.1$fitted, 1)
 
 __
 R-help@stat.math.ethz.ch 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.

-- 
Andrew Robinson  
Department of Mathematics and StatisticsTel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/

__
R-help@stat.math.ethz.ch 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.