Obscure message: Error in `contrasts<-`... ?

questions concerning anlysis/theory using program DENSITY and R package secr. Focus on spatially-explicit analysis.

Obscure message: Error in `contrasts<-`... ?

Postby murray.efford » Thu Feb 21, 2013 7:16 pm

A user came up with this obscure error message from mask.check():
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

The message comes from the R function model.matrix which is called by secr.design.MS which is called by secr.fit which is called by mask.check! Obviously there is a problem with a factor. In this case the fitted model had specified groups using an individual covariate 'sex', but within each session only one sex was present, so the grouping factor had only one level. The same error would be expected from secr.fit, and from other functions that call secr.design.MS.

The solution is easy: use 'groups' only when there is more than one group :)

Murray

P.S. You can reproduce the message with
Code: Select all
cars$type <- rep('n',50)  ## add dummy factor to dataset 'cars'
model.matrix(dist ~ type, data = cars)
## compare
cars$type <- rep(c('n','p'),25)
model.matrix(dist ~ type, data = cars)
murray.efford
 
Posts: 712
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Return to analysis help

Who is online

Users browsing this forum: No registered users and 4 guests