[R] Extracting the names of coefficients of random effects

Brian Willis b.h.willis at bham.ac.uk
Sat Apr 19 17:51:19 CEST 2014


Hi All,
I need to be able to manipulate the names of the coefficients from
*ranef()*.

If there is any missing data when fitting a mixed model using lmer, no
estimate is returned for the associated level for that random effect. Thus
if the data input for regions had levels 
	*Region*
        Bolton
	Bradford                              	         				                                	  
        Cambridge		                                                 
        Durham						 
and there was missing data on Bradford then 
* ranef(model)*					gives 
	                                                     (Intercept)
Bolton:                               	          -0.0981763413
Cambridge		                                   0.0151102347
Durham						   0.1837142259

This becomes a problem if I want to use *predict( )* on new data where there
is no missing data on Bradford. In such an instance

	*predict (model, newdata = newInput) *	gives the following error message 

             ‘Error in (function (x, n)  : new levels detected in newdata’

I could get round this by checking the Region field of the new data
‘newInput’ against the names of the levels of the intercept coefficients
from* ranef().*
However, I’m not sure how to access these since if 
*x<- ranef(model)
x *
This gives the same output above, but

	*x[1,1]* only returns the numeric value  -0.0981763413

x is a dataframe with only one field (column) with numeric values and the
names of the levels are not present or identified. There must be a variable
which defines ‘Bolton’, Bradford’ etc since if I use the write.table
function
*write.table (x, file="/desktop/Dummy.csv", sep = ",",  col.names = NA, 
qmethod = "double")*
This outputs both the names (‘Bolton’, Bradford’..) and their corresponding
numeric values to a spreadsheet.

Does anyone know how to do this without resorting to outputting to a
spreadsheet?
 
Regards,

Brian H Willis
Health and Population Sciences
University of Birmingham




--
View this message in context: http://r.789695.n4.nabble.com/Extracting-the-names-of-coefficients-of-random-effects-tp4689109.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list