Merci par avance de votre aide
Code : Tout sélectionner
newFormulaOffset <- function (formula) {
terms <- attributes(terms.formula(formula))$term.labels
fixEff <- terms[-grep("|",terms,fixed=T)]
randEff <- terms[grep("|",terms,fixed=T)]
newFormula <- paste(formula[[2]],"~")
if (length(fixEff)>=1) {
newFormula <- paste(newFormula,fixEff[1])
for (i in 2:length(fixEff)) {
newFormula <- paste(newFormula,fixEff[i],sep=" + ")
}
} else {}
if (length(randEff)!=0) {
newFormula <- paste(newFormula,"+(",randEff,")")
} else {}
newFormula <- as.formula(paste(newFormula,"offset(trajTypique)",sep=" + "),env=parent.frame())
return(newFormula)
}
# newFormulaOffset(formula=y~x+z+(1|id))