run.exp<-function(co2=0,eau=0) { x<-co2; y<-eau; mu<-10; tot.n<-60; if(x<=0) { x<-as.numeric(readline(prompt="Combien de niveaux 'co2': ")); if(x<2) { stop("Il faut au moins deux niveaux!",call.=FALSE); } } if(y<=0) { y<-as.numeric(readline(prompt="Combien de niveaux 'eau': ")); if(y<2) { stop("Il faut au moins deux niveaux!",call.=FALSE); } } per.x<-round(tot.n/x); cell.n<-round(per.x/y); per.x<-cell.n*y; per.y<-cell.n*x; tot.n<-cell.n*x*y if(per.x<(2*y) | per.y<(2*x)) { stop(paste("Vous n'avez que 60 données au total. Impossible de les répartir dans un design de",x,"X",y,"en ayant deux réplicats par traitement. Il en faudrait",x*y*2,"au total."),call.=FALSE); } seq.x<-c(seq(0.5,0.8,length.out=10),seq(0.9,1.2,length.out=90)); step<-round(length(seq.x)/(x-1))-1; f.x<-rep(seq.x[seq(1,by=step,length.out=x)],each=per.x); seq.y<-c(seq(-1,1.5,by=0.02),seq(0.7,-1,by=-0.02)); step<-round(length(seq.y)/(y-1))-1; f.y<-rep(seq.y[seq(1,by=step,length.out=y)],per.y); CO2<-factor(rep(1:x,each=per.x)); eau<-factor(rep(1:y,per.y)); # not used anymore # inter<-numeric(tot.n); p.inter<-which(f.y==f.y[1]); inter[p.inter]<-rnorm(length(p.inter),0,0.1); #################### error<-rnorm(tot.n,0,0.5); croissance<-mu+f.x+f.y+error; par(mfrow=c(1,3)); boxplot(croissance~CO2, ylab="Croissance [jour]", xlab="Quantité CO2 [1=minimum]"); boxplot(croissance~eau, ylab="Croissance [jour]", xlab="Quantité eau [1=minimum]"); interaction.plot(CO2,eau,croissance); anova(lm(croissance~CO2*eau)); }