Dear Rusers, The default behavior in R when performing a regression model with missing values is to exclude any case that contains a missing value? How could i set the bahavior that R deal with missing values? e.g.: exclude cases listwise exclude cases pairwise replace with mean Thanks very much! -- Kind Regards, Zhi Jie,Zhang ,PHD Department of Epidemiology School of Public Health Fudan University Tel:86-21-54237149 [[alternative HTML version deleted]]
Dear Rusers, The default behavior in R when performing a regression model with missing values is to exclude any case that contains a missing value? How could i set the bahavior that R deal with missing values? e.g.: exclude cases listwise exclude cases pairwise replace with mean Thanks very much! -- Kind Regards, Zhi Jie,Zhang ,PHD Department of Epidemiology School of Public Health Fudan University Tel:86-21-54237149 [[alternative HTML version deleted]]
Ferdinand Alimadhi
2006-Jul-13 15:38 UTC
[R] set the bahavior that R deal with missing values?
You can deal with the missing values before performing any regression model. if you dataset is : > D X1 X2 X3 1 NA 2 4 2 1 NA NA 3 2 2 6 4 NA 34 NA 5 3 NA 7 then the following will replace all NA with the mean value > f<-function(col){ + col[is.na(col)]<-mean(col,na.rm=TRUE) + col} > sapply(D,f) X1 X2 X3 [1,] 2 2.00000 4.000000 [2,] 1 12.66667 5.666667 [3,] 2 2.00000 6.000000 [4,] 2 34.00000 5.666667 [5,] 3 12.66667 7.000000 Hope this is what you want. zhijie zhang wrote:>Dear Rusers, >The default behavior in R when performing a regression model with missing >values is to exclude any case that contains a >missing value? How could i set the bahavior that R deal with missing values? >e.g.: >exclude cases listwise >exclude cases pairwise >replace with mean > >Thanks very much! > > >-- Ferdinand Alimadhi Programmer / Analyst Harvard University The Institute for Quantitative Social Science (617) 496-0187 falimadhi at iq.harvard.edu www.iq.harvard.edu
zhijie zhang <epistat <at> gmail.com> writes:> The default behavior in R when performing a regression model with missing > values is to exclude any case that contains a > missing value? How could i set the bahavior that R deal with missing values?Difficult to say, since there is no such thing as a regression model in R, but certainly more than a few dozens in several packages. Best show a self-contained runnably sample where you would prefer some na.action (see, for example, parameter na.action in lm). Dieter