[R] find confounder in covariates

Spencer Graves spencer.graves at pdf.com
Sat Jul 23 02:26:34 CEST 2005


	  It was easier than I thought.  To your example, just add one line:

 > alias(f)
Model :
y ~ z1 + z2 + z3

Complete :
      (Intercept) z1B z1C z3
z2Bb              1
z2Cc                  1

	  spencer graves

Young Cho wrote:

> Hi,
> 
> I was wondering if there is a way, or function in R to
> find confounders. For istance, 
> 
> 
>>a = sample( c(1:3), size=10,replace=T)
>>X1 = factor( c('A','B','C')[a] )
>>X2 = factor( c('Aa','Bb','Cc')[a] )
>>Xmat = data.frame(X1,X2,rnorm(10),rnorm(10))
>>dimnames(Xmat)[[2]] = c('z1','z2','z3','y')
> 
> 
> Now, z2 is just an alias of z1. There can be a
> collinearity like one is a linear combination of
> others. If you run lm on it:
>  
> 
>>f = lm(y~.,data=Xmat)
>>summary(f)
> 
> 
> Call:
> lm(formula = y ~ ., data = Xmat)
> 
> Residuals:
>     Min      1Q  Median      3Q     Max 
> -1.2853 -0.3708 -0.1224  0.4617  1.2821 
> 
> Coefficients: (2 not defined because of singularities)
>             Estimate Std. Error t value Pr(>|t|)  
> (Intercept)  0.82141    0.44583   1.842   0.1150  
> z1B         -1.34167    0.65176  -2.059   0.0852 .
> z1C          0.80891    1.07639   0.751   0.4808  
> z2Bb              NA         NA      NA       NA  
> z2Cc              NA         NA      NA       NA  
> z3           0.04231    0.23397   0.181   0.8625  
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.'
> 0.1 ' ' 1 
> 
> Residual standard error: 0.971 on 6 degrees of freedom
> Multiple R-Squared: 0.5086,     Adjusted R-squared:
> 0.2629 
> F-statistic:  2.07 on 3 and 6 DF,  p-value: 0.2057 
> 
> In this case, I can look at data and figure out which
> variable is confounded with which. But, if we have
> many categorial covariates ( not necessarily same
> number of levels ), it is almost impossible to check
> it out.  
> 
> Any help would be greatly appreicated. Thanks.
> 
> Young.
> 
> ______________________________________________
> R-help at 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

-- 
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