This group impresses me, so far I have been helped with all my questions within 24 hours. Thanks. Therefore another one. I am used to programs (such as STATA) where observations with missing values that are included in a model are simply ignored in the analysis. So far I have not been able to figure out how to deal with missing values in R and have solved the problem by deleting observations with missing values before loading them into R. Can anyone give me a hint on how to do this in a simpler way? Sincerely, Dr. Tor A Strand Centre for International Health Haukeland Hospital University of Bergen 5021 Bergen Norway Phone: (country prefix 47) Residence:56 51 10 88, office: 55 97 49 80, fax: 55 97 49 79, cellular: 90 97 10 86
On Wednesday 16 July 2003 12:11, Tor A Strand wrote:> This group impresses me, so far I have been helped with all my > questions within 24 hours. Thanks. > > Therefore another one. > > I am used to programs (such as STATA) where observations with > missing values that are included in a model are simply ignored in > the analysis. So far I have not been able to figure out how to deal > with missing values in R and have solved the problem by deleting > observations with missing values before loading them into R. > > Can anyone give me a hint on how to do this in a simpler way?R can deal with NAs in several ways, look at help(na.omit) Many methods, e.g., lm(), also take an na.action argument so that you can keep your data frame with the NAs in R, but fit linear models only on the complete cases for example. Best, Z> Sincerely, > > > Dr. Tor A Strand > Centre for International Health > Haukeland Hospital > University of Bergen > 5021 Bergen > Norway > Phone: (country prefix 47) > Residence:56 51 10 88, office: 55 97 49 80, > fax: 55 97 49 79, cellular: 90 97 10 86 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
There are many packages that handles missing values, aka imputations.>From memory Hmisc is one of them. But you can certainly search throughCRAN. On Wed, 16 Jul 2003, Tor A Strand wrote:> Date: Wed, 16 Jul 2003 12:11:32 +0200 > From: Tor A Strand <Tor.Strand at cih.uib.no> > To: R-list <r-help at stat.math.ethz.ch> > Subject: [R] how to handle missing values > > This group impresses me, so far I have been helped with all my questions > within 24 hours. Thanks. > > Therefore another one. > > I am used to programs (such as STATA) where observations with missing values > that are included in a model are simply ignored in the analysis. So far I > have not been able to figure out how to deal with missing values in R and > have solved the problem by deleting observations with missing values before > loading them into R. > > Can anyone give me a hint on how to do this in a simpler way? > >-- Cheers, Kevin ------------------------------------------------------------------------------ "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage (1791-1871) ---- From Computer Stupidities: http://rinkworks.com/stupid/ -- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki)
This really depends on what you want to do. I will try to give some example below. 1. Coding the missing values But you definitely do not need to delete observations BEFORE loading them into R. By default any empty cells or "NA" is treated as NA, when you load the data using read.delim(). You can adjust the na.string option in read.delim() to change this default behaviour. Ensure the coding is ok before you proceed. You can check using is.na() for example to see if R will treat them as missing values. 2. Perform calculations with missing values as defined by na.action() X <- c(1,2,3,NA, 4) sum(X, na.rm=T) # gives you 10 See ?na.action for more interestin detail. Some algorithms are capable of automatically handle missing values. In the classification context, rpart can handle missing values. 3. Missing value imputation There are many imputation methods (eg. EMV, e1071, hmisc, norm, permax, pamr libraries). The type of imputation depends on your application, area of research and type of missingness (if at missing completely at random, missing/observed at random, informative missing). Good luck. -----Original Message----- From: Tor A Strand [mailto:Tor.Strand at cih.uib.no] Sent: Wednesday, July 16, 2003 6:12 PM To: R-list Subject: [R] how to handle missing values This group impresses me, so far I have been helped with all my questions within 24 hours. Thanks. Therefore another one. I am used to programs (such as STATA) where observations with missing values that are included in a model are simply ignored in the analysis. So far I have not been able to figure out how to deal with missing values in R and have solved the problem by deleting observations with missing values before loading them into R. Can anyone give me a hint on how to do this in a simpler way? Sincerely, Dr. Tor A Strand Centre for International Health Haukeland Hospital University of Bergen 5021 Bergen Norway Phone: (country prefix 47) Residence:56 51 10 88, office: 55 97 49 80, fax: 55 97 49 79, cellular: 90 97 10 86 ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Tor A Strand
2003-Jul-17 06:29 UTC
[R] missing values and gam (was: how to handle missing values)
Thank you for all the responses on generalized additive models(gam) and missing values. I am now able set up a model using gam and have a certain understanding of how R deals with missing values. The problem is, however, I am still not able to a gam model that is from a dataset that contains missing values. The function C<-gam(depvar~var1+var2+s(var3), data=dataset) Returns the errors Error in na.omit.default() : Argument "object" is missing, with no default Again, can anyone help a newbie. Tor