Modérateur : Groupe des modérateurs
Code : Tout sélectionner
cbind(succes, echec) ~ x1 + x2...
Code : Tout sélectionner
cbind(deces, n - deces) ~ x1 + x2...
Code : Tout sélectionner
> set.seed(12321)
> n <- rep(20, 10)
> y <- rbinom(10, 20, .2)
> x <- factor(sample(c("A", "B"), 10, replace = TRUE))
>
> glm(cbind(y, n - y) ~ x, family = binomial)
Call: glm(formula = cbind(y, n - y) ~ x, family = binomial)
Coefficients:
(Intercept) xB
-1.1371 -0.4724
Degrees of Freedom: 9 Total (i.e. Null); 8 Residual
Null Deviance: 16.24
Residual Deviance: 14.76 AIC: 48.05
> glm(y/n ~ x, weights = n, family = binomial)
Call: glm(formula = y/n ~ x, family = binomial, weights = n)
Coefficients:
(Intercept) xB
-1.1371 -0.4724
Degrees of Freedom: 9 Total (i.e. Null); 8 Residual
Null Deviance: 16.24
Residual Deviance: 14.76 AIC: 48.05
Code : Tout sélectionner
> p=c(10,33,20,9,6,56,39,24)
> n=c(59,92,57,32,13,95,61,35)
> y=p/n
> x1=c(1,3,4,4,4,5,5,6)
> x2=c(5,9,9,9,11,13,14,14)
> x3=c(21,21,21,23,23,23,23,23)
> y=factor(y)
> X1=log(x1)
> X2=log(x2)
> X3=log(x3)
> reglog=data.frame(y,X1,X2,X3)
> model=glm(y~(X1+X2+X3)^3,reglog,family=binomial,weights=n)
> model
Call: glm(formula = y ~ (X1 + X2 + X3)^3, family = binomial, data = reglog, weights = n)
Coefficients:
(Intercept) X1 X2 X3 X1:X2 X1:X3 X2:X3 X1:X2:X3
-291.07 -849.83 776.27 32.35 -58.82 321.05 -221.54 NA
Degrees of Freedom: 7 Total (i.e. Null); 1 Residual
Null Deviance: 347.9
Residual Deviance: 3.063e-10 AIC: 14
Rollot Fabien a écrit :Ok, donc si je comprend bien la commande cbind remplace en quelque sorte l'option weights?
Je pensais faire comme suis pour expliquer la probabilité de décès,avec p le nombre de décés, n le nombre total d'insecte pour l'essai et x1,x2,x3 des concentrations de produits.
Dois-je utiliser cbind alors?
j'espere que vous arriverez à lire!Code : Tout sélectionner
> p=c(10,33,20,9,6,56,39,24)
> n=c(59,92,57,32,13,95,61,35)
> y=p/n
> x1=c(1,3,4,4,4,5,5,6)
> x2=c(5,9,9,9,11,13,14,14)
> x3=c(21,21,21,23,23,23,23,23)
> y=factor(y)
> X1=log(x1)
> X2=log(x2)
> X3=log(x3)
> reglog=data.frame(y,X1,X2,X3)
> model=glm(y~(X1+X2+X3)^3,reglog,family=binomial,weights=n)
> model
Call: glm(formula = y ~ (X1 + X2 + X3)^3, family = binomial, data = reglog, weights = n)
Coefficients:
(Intercept) X1 X2 X3 X1:X2 X1:X3 X2:X3 X1:X2:X3
-291.07 -849.83 776.27 32.35 -58.82 321.05 -221.54 NA
Degrees of Freedom: 7 Total (i.e. Null); 1 Residual
Null Deviance: 347.9
Residual Deviance: 3.063e-10 AIC: 14
Code : Tout sélectionner
> p=c(10,33,20,9,6,56,39,24)
> n=c(59,92,57,32,13,95,61,35)
> y=p/n
> x1=c(1,3,4,4,4,5,5,6)
> x2=c(5,9,9,9,11,13,14,14)
> x3=c(21,21,21,23,23,23,23,23)
> y=factor(y)
> X1=log(x1)
> X2=log(x2)
> X3=log(x3)
> reglog=data.frame(y,X1,X2,X3)
> model=glm(cbind(p,n-p)~(X1+X2+X3)^3,reglog,family=binomial)
> model
Call: glm(formula = cbind(p, n - p) ~ (X1 + X2 + X3)^3, family = binomial, data = reglog)
Coefficients:
(Intercept) X1 X2 X3 X1:X2 X1:X3 X2:X3 X1:X2:X3
-22.349 -14.896 21.958 5.795 1.209 3.981 -6.576 NA
Degrees of Freedom: 7 Total (i.e. Null); 1 Residual
Null Deviance: 54.27
Residual Deviance: 0.09681 AIC: 47.5
glm(formula, family = gaussian, data, weights, subset,
na.action, start = NULL, etastart, mustart,
offset, control = glm.control(...), model = TRUE,
method = "glm.fit", x = FALSE, y = TRUE, contrasts = NULL,
...)
Code : Tout sélectionner
> p = c(10,33,20,9,6,56,39,24)
> n = c(59,92,57,32,13,95,61,35)
> x1 = c(1,3,4,4,4,5,5,6)
> x2 = c(5,9,9,9,11,13,14,14)
> x3 = c(21,21,21,23,23,23,23,23)
> X1 = log(x1)
> X2 = log(x2)
> X3 = log(x3)
> reglog <- data.frame(p,n,X1,X2,X3)
> model <- glm((p/n)~(X1+X2+X3)^3,data=reglog,family=binomial,weights=n)
> model1 <- glm(cbind(p,n-p)~(X1+X2+X3)^3,data=reglog,family=binomial)
> model
Call: glm(formula = (p/n) ~ (X1 + X2 + X3)^3, family = binomial, data = reglog, weights = n)
Coefficients:
(Intercept) X1 X2 X3 X1:X2 X1:X3 X2:X3 X1:X2:X3
-22.349 -14.896 21.958 5.795 1.209 3.981 -6.576 NA
Degrees of Freedom: 7 Total (i.e. Null); 1 Residual
Null Deviance: 54.27
Residual Deviance: 0.09681 AIC: 47.5
> model1
Call: glm(formula = cbind(p, n - p) ~ (X1 + X2 + X3)^3, family = binomial, data = reglog)
Coefficients:
(Intercept) X1 X2 X3 X1:X2 X1:X3 X2:X3 X1:X2:X3
-22.349 -14.896 21.958 5.795 1.209 3.981 -6.576 NA
Degrees of Freedom: 7 Total (i.e. Null); 1 Residual
Null Deviance: 54.27
Residual Deviance: 0.09681 AIC: 47.5
Retourner vers « Questions en cours »
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité