r的多变量logistic回归?

如何在R中执行多变量(多个因变量)逻辑回归?

我知道你这样做是为了线性回归,这是有效的

form <-cbind(A,B,C,D)~shopping_pt+price
mlm.model.1 <- lm(form, data = train)

但是,当我尝试以下(见下文)进行逻辑回归时,它不起作用.

model.logistic <- glm(form, family=binomial(link=logit), data=train)

谢谢您的帮助.

要添加,似乎我使用上述线性模型执行此操作的代码可能不正确.我正在尝试本文档中概述的内容,其中一些可能会有用.

ftp://ftp.cis.upenn.edu/pub/datamining/public_html/ReadingGroup/papers/multiResponse.pdf

最佳答案 在我看来,lm(cbind(A,B,C,D)~shopping_pt价格)恰好适合四个因变量的四种不同模型.您提供的
second link甚至提到:

The individual coefficients, as well as their standard errors will be the same as those produced by the multivariate regression. However, the OLS regressions will not produce multivariate results, nor will they allow for testing of coefficients across equations.

意味着所有估计都是相同的,你只需要预测四次;拟合系数的假设在模型中是独立的.

我刚刚尝试了下面这个例子,表明它看起来确实如此:

> set.seed(0)
> x1 <- runif(10)
> x2 <- runif(10)
> y1 <- 2*x1 + 3*x2 + rnorm(10)
> y2 <- 4*x1 + 5*x2 + rnorm(10)
> mm <- lm(cbind(y1,y2)~x1+x2)
> m1 <- lm(y1~x1+x2)
> m2 <- lm(y2~x1+x2)
# If we look at mm, m1 and m2, we see that models are identical
# If we predict new data, they give the same estimates
> x1_ <- runif(10)
> x2_ <- runif(10)
> predict(mm, newdata=list(x1=x1_, x2=x2_))
          y1       y2
1  2.9714571 5.965774
2  2.7153855 5.327974
3  2.5101344 5.434516
4  1.3702441 3.853450
5  0.9447582 3.376867
6  2.3809256 5.051257
7  2.5782102 5.544434
8  3.1514895 6.156506
9  2.4421892 5.061288
10 1.6712042 4.470486
> predict(m1, newdata=list(x1=x1_, x2=x2_))
        1         2         3         4         5         6         7         8         9        10 
2.9714571 2.7153855 2.5101344 1.3702441 0.9447582 2.3809256 2.5782102 3.1514895 2.4421892 1.6712042 
> predict(m2, newdata=list(x1=x1_, x2=x2_))
       1        2        3        4        5        6        7        8        9       10 
5.965774 5.327974 5.434516 3.853450 3.376867 5.051257 5.544434 6.156506 5.061288 4.470486

所以这表明你可以分别适应四种物流模型.

点赞