Hello everyone, I am trying to fit the following model All X. variables are continuous, while the conditions are categoricals. model <- lm(X2 +X3+X4+X5+X6+X7+X8+X9+X10+X11+X12+X13+X14+X15+X16+X17+X18+X19+X20+X21+X22+X23+X24+X25+X26+X27+X28+X29+X30+X31+X32+X33+X34+X35+X36+X37+X38+X39+X40+X41+X42+X43+X44+X45+X46+X47+X48+X49+X50+X51+X52+X53+X54+X55+X56+X57+X58+X59+X60+X61+X62+X63+X64+X65+X66+X67+X68+X69+X70+X71+X72+X73+X74+X75+X76+X77+X78+X79+X80+X81+X82+X83+X84+X85+X86+X87+X88+X89+X90+X91+X92+X93+X94+X95+X96+X97+X98+X99+X100+X101+X102+X103+X104+X105+X106+X107+X108+X109+X110+X111+X112+X113+X114+X115+X116+X117+X118+X119+X120+X121+X122+X123+X124+X125+X126+X127+X128+X129+X130+X131+X132+X133+X134+X135+X136+X137+X138+X139+X140+X141+X142+X143+X144+X145+X146+X147+X148+X149+X150+X151+X152 ~ conditions, data = proteo) but I get this error message: Error in model.matrix.default(mt, mf, contrasts) : model frame and formula mismatch in model.matrix() can someone help me please? Julien. -- View this message in context: http://r.789695.n4.nabble.com/model-frame-and-formula-mismatch-in-model-matrix-tp4664093.html Sent from the R help mailing list archive at Nabble.com.
Eva Prieto Castro
2013-Apr-13 06:47 UTC
[R] model frame and formula mismatch in model.matrix()
Hi Julien,>From my point of view this error may be produced by the fact you are working with a lot of variables, so the number of characters if you take them into account as character is bigger than the system can support.Have you tried to test an example with 50 variables, for example?. See you the error message in function code:> model.matrix.defaultfunction (object, data = environment(object), contrasts.arg = NULL, xlev = NULL, ...) { t <- if (missing(data)) terms(object) else terms(object, data = data) if (is.null(attr(data, "terms"))) data <- model.frame(object, data, xlev = xlev) else { reorder <- match(sapply(attr(t, "variables"), deparse, width.cutoff = 500)[-1L], names(data)) if (any(is.na(reorder))) stop("model frame and formula mismatch in model.matrix()") if (!identical(reorder, seq_len(ncol(data)))) data <- data[, reorder, drop = FALSE] } int <- attr(t, "response") if (length(data)) { contr.funs <- as.character(getOption("contrasts")) namD <- names(data) for (i in namD) if (is.character(data[[i]])) { data[[i]] <- factor(data[[i]]) warning(gettextf("variable '%s' converted to a factor", i), domain = NA) } isF <- sapply(data, function(x) is.factor(x) || is.logical(x)) isF[int] <- FALSE isOF <- sapply(data, is.ordered) for (nn in namD[isF]) if (is.null(attr(data[[nn]], "contrasts"))) contrasts(data[[nn]]) <- contr.funs[1 + isOF[nn]] if (!is.null(contrasts.arg) && is.list(contrasts.arg)) { if (is.null(namC <- names(contrasts.arg))) stop("invalid 'contrasts.arg' argument") for (nn in namC) { if (is.na(ni <- match(nn, namD))) warning(gettextf("variable '%s' is absent, its contrast will be ignored", nn), domain = NA) else { ca <- contrasts.arg[[nn]] if (is.matrix(ca)) contrasts(data[[ni]], ncol(ca)) <- ca else contrasts(data[[ni]]) <- contrasts.arg[[nn]] } } } } else { isF <- FALSE data <- data.frame(x = rep(0, nrow(data))) } ans <- .Internal(model.matrix(t, data)) cons <- if (any(isF)) lapply(data[isF], function(x) attr(x, "contrasts")) else NULL attr(ans, "contrasts") <- cons ans } Regards, Eva --- El vie, 12/4/13, jul 2-pom <j.pompon@ibmc-cnrs.unistra.fr> escribió: De: jul 2-pom <j.pompon@ibmc-cnrs.unistra.fr> Asunto: [R] model frame and formula mismatch in model.matrix() Para: r-help@r-project.org Fecha: viernes, 12 de abril, 2013 21:05 Hello everyone, I am trying to fit the following model All X. variables are continuous, while the conditions are categoricals. model <- lm(X2 +X3+X4+X5+X6+X7+X8+X9+X10+X11+X12+X13+X14+X15+X16+X17+X18+X19+X20+X21+X22+X23+X24+X25+X26+X27+X28+X29+X30+X31+X32+X33+X34+X35+X36+X37+X38+X39+X40+X41+X42+X43+X44+X45+X46+X47+X48+X49+X50+X51+X52+X53+X54+X55+X56+X57+X58+X59+X60+X61+X62+X63+X64+X65+X66+X67+X68+X69+X70+X71+X72+X73+X74+X75+X76+X77+X78+X79+X80+X81+X82+X83+X84+X85+X86+X87+X88+X89+X90+X91+X92+X93+X94+X95+X96+X97+X98+X99+X100+X101+X102+X103+X104+X105+X106+X107+X108+X109+X110+X111+X112+X113+X114+X115+X116+X117+X118+X119+X120+X121+X122+X123+X124+X125+X126+X127+X128+X129+X130+X131+X132+X133+X134+X135+X136+X137+X138+X139+X140+X141+X142+X143+X144+X145+X146+X147+X148+X149+X150+X151+X152 ~ conditions, data = proteo) but I get this error message: Error in model.matrix.default(mt, mf, contrasts) : model frame and formula mismatch in model.matrix() can someone help me please? Julien. -- View this message in context: http://r.789695.n4.nabble.com/model-frame-and-formula-mismatch-in-model-matrix-tp4664093.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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. [[alternative HTML version deleted]]
Hi Eva, you're right, it works with 50 variables. Then, how could I change this variable limit in the lm function? Thank you very much for your help. Julien. -- View this message in context: http://r.789695.n4.nabble.com/model-frame-and-formula-mismatch-in-model-matrix-tp4664093p4664226.html Sent from the R help mailing list archive at Nabble.com.