[R] loglinear model selection

Spencer Graves spencer.graves at pdf.com
Sun Sep 4 03:05:03 CEST 2005


	  Does the following help you:

library(MASS)

set.seed(1)
x1 <- rep(1:2, 2)
x2 <- rep(1:2, each=2)
DF <- data.frame(x1=x1, x2=x2, y=rbinom(4, 1000,
           prob=(x1+x2-1.5)/3)/1000)

fit0 <- glm(y~1, family=binomial, data=DF,
            weights=rep(1000, 4))
stepAIC(fit0, y~x1+x2)

	  spencer graves

Bernardo Rangel Tura wrote:

> Hi R-masters!
> 
> I have a problem and need your help.
> I have 9 discrete variables with 2 levels each.
> In exploratory analisys I generate one matrix with chi-square for tables 
> with 2 ariables each with this script
> 
> setwd("F:/")
> dados<-read.csv("log.csv")[,2:10]
> dados.x<-matrix(NA,ncol=9,nrow=9)
> for(i in 1:8){
> for(j in (i+1):9){
> tab<-table(dados[,i],dados[,j])
> dados.x[i,j]<-round(as.numeric(chisq.test(tab)$statistic),3)
> dados.x[j,i]<-round(as.numeric(chisq.test(tab)$statistic),3)
>   }
> }
> dados.x
> 
> The result is:
> 
>         [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]  [,8]   [,9]
>   [1,]    NA  3.589  6.351  3.957  4.269  0.851  2.955 1.188  1.975
>   [2,] 3.589     NA  9.664 24.596 12.510 26.284  8.580 3.608  6.574
>   [3,] 6.351  9.664     NA 25.054 10.300 12.189 19.811 0.192 11.744
>   [4,] 3.957 24.596 25.054     NA 50.032 35.587 22.401 1.950 26.631
>   [5,] 4.269 12.510 10.300 50.032     NA 80.876 54.954 0.127 61.573
>   [6,] 0.851 26.284 12.189 35.587 80.876     NA 57.346 0.741 49.738
>   [7,] 2.955  8.580 19.811 22.401 54.954 57.346     NA 1.520 80.615
>   [8,] 1.188  3.608  0.192  1.950  0.127  0.741  1.520    NA  0.311
>   [9,] 1.975  6.574 11.744 26.631 61.573 49.738 80.615 0.311     NA
> 
> Now I need fit a loglinear model with this variables, but I need know have 
> a command with generate ALL models with the set this 8 vairables (ALL minus 
> [,8]) incluindind the interactions.
> 
> Can Anyone Help me?
> 
> 
> 
> Thanks in advance
> 
> Bernardo Rangel Tura, MD, MSc
> National Institute of Cardiology Laranjeiras
> Rio de Janeiro Brazil 
> 
> 

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list