[R] Advice on an appropriate condition for warning in a function

Mike Rennie mrennie at utm.utoronto.ca
Mon Jan 22 06:05:18 CET 2007

Hi, there

I have written a function that will allow me to calculate the variance 
components for a model II (random effects) single factor ANOVA (perhaps this is 
me re-inventing the wheel, but I handn't yet come across anything in R that 
does this for me, but I'm sure people will let me know from this posting if 
there are). The function takes as it's argument an object which holds the 
results of an lm call. e.g.,


The function is as follows (some comments included):

		anovmod<-anova(object.lm) #get the anova table for the lm
		MStreat<-anovmod[1,3]; MSErr<-anovmod[2,3] #extract Mean Squares
		dataframe<- as.data.frame(object.lm[13]) 		
		ni <- tapply(dataframe[,1], dataframe[,2], length) 		
		stot<-s2a + MSErr
		list(treat.var.comp=s2a, err.var.comp=MSErr, 			
		p.var.treat=treatvar, p.var.err=errorvar)

I'd like to include a "warning" statement in the function that 
returns 'function requires arguments that are objects of the form obj<-lm
(y~x)', but I need a case to evaluate the object against in order to throw the 

Any advice? 

I feel like my best opportunity is after the first line into the function, 
where I ask for the ANOVA table. Since this is a 2 X 5 table, presumably I 
should be able to evaluate it against the size of that table? Any thoughts on 
how to check that? I welcome any suggestions.



Michael Rennie
Ph.D. Candidate, University of Toronto at Mississauga
3359 Mississauga Rd. N.
Mississauga, ON  L5L 1C6
Ph: 905-828-5452  Fax: 905-828-3792

More information about the R-help mailing list