[R] "drop if missing" command?

David Winsemius dwinsemius at comcast.net
Sat Feb 13 15:07:34 CET 2010


On Feb 12, 2010, at 6:48 PM, Nora Kozloff wrote:

> This will probably seem very simple to experienced R programmers:
>
> I am doing a snp association analysis and am at the model-fitting  
> stage. I
> am using  the Stats package's  "drop1" with the following code:
> ##geno is the dataset
> ## the dependent variable (casectrln) is dichotomous and coded 0,1
> ##  rs743572_2 is one of the snps (which is coded 0,1,2 for the 3  
> genotypes)
>
> library(stats)
>
> modadd = glm(geno$casectrln ~rs743572_2 + factor(racegrp)+  
> factor(smokgp)+
> factor(alcgp)+ factor(bmigp) + factor(ipssgp)
> + agebase, family="binomial")
> drop1(mod,scale=0,test=c("Chisq"), x=NULL, k=2)
>
> There is a great deal of missing data in this dataset for both snps  
> and for
> covariates--so I have been instructed not to simply drop all cases  
> with
> missing genotype or covariate data .

It sounds as though you have been asked to do some sort of imputation  
of missing data.

> How can I drop the observations which
> are missing  only for the snp I am modeling at the time, then  
> reinstate
> those observations to model the next snp?
>
> Thanks for any help,
>
> Nora
-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list