Hello R Users,
I am having difficulty deleting the last warning message in a loop so that the only warning that is produced is that from the most recent line of code. I have tried options(warn=1), rm(last.warning), and resetting the last.warning using something like: > warning("Resetting warning message") This problem has been addressed in a previous listserve string, however I do not follow the advice given. See the below web link. Any help would be greatly appreciated. Thanks! Aaron Wells https://stat.ethz.ch/pipermail/r-help/2008-October/176765.html A general example is first, followed by an example with the loop. --------------------------------------------------------------------------------------------------------------------------------------------- Example 1: > demo.glm<-glm(test.data[,1]~c(1:38)+I(c(1:38)^2),family=binomial) ### > Generalized linear model run on the first column of my example data > warnings() ### no warnings reported NULL > demo.glm<-glm(test.data[,9]~c(1:38)+I(c(1:38)^2),family=binomial) ### > Generalized linear model run on the 9th column of my example data Warning messages: 1: In glm.fit(x = X, y = Y, weights = weights, start = start, etastart = etastart, : algorithm did not converge 2: In glm.fit(x = X, y = Y, weights = weights, start = start, etastart = etastart, : fitted probabilities numerically 0 or 1 occurred > warnings() ### the model with column 9 as data produces warnings Warning messages: 1: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : algorithm did not converge 2: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : fitted probabilities numerically 0 or 1 occurred > demo.glm<-glm(test.data[,1]~c(1:38)+I(c(1:38)^2),family=binomial) ### Re-run > the model with column 1 as data > warnings() ### reports the same warnings from the column 9 model, ideally > it would report the actual warning message for the column 1 model ("NULL") as > above Warning messages: 1: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : algorithm did not converge 2: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : fitted probabilities numerically 0 or 1 occurred ---------------------------------------------------------------------------------------------------------------------------------------------- Example 2: Loop ###In the below example I have reset warnings() before each iteration by using warning("Resetting warning message"). I would like the warnings to somehow be consolidated into a list that I could later examine to determine which model iterations ran with and without warnings. The below code doesn't work because the functions are being run in the loop environment, and not the base environment. > test.warn<-rep(0,ncol(test.data));test.warn<-as.list(test.warn) > > > for (i in 1:ncol(test.data)) {warn.reset<-warning("Resetting warning message") + demo.glm<-glm(test.data[,i]~c(1:38)+I(c(1:38)^2),family=binomial) + warn.new<-warnings() + cbind.warn<-cbind(warn.reset,warn.new) + test.warn[[i]]<-cbind.warn + test.warn + } There were 38 warnings (use warnings() to see them) > test.warn [[1]] warn.reset warn.new Resetting warning message "Resetting warning message" NULL [[2]] warn.reset warn.new Resetting warning message "Resetting warning message" NULL . . . Aaron F. Wells, PhD Senior Scientist ABR, Inc. 2842 Goldstream Road Fairbanks, AK 99709 _________________________________________________________________ [[elided Hotmail spam]] plorer 8. [[elided Hotmail spam]] [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.