[R] find confounder in covariates
Young Cho
iidn01 at yahoo.com
Fri Jul 22 03:47:09 CEST 2005
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.
More information about the R-help
mailing list