MATLAB 中的 glmfit 与 R 中的 glm .. 得到不同的答案

glmfit in MATLAB vs glm in R.. getting different answers

% A set of car weights\
weight = [0.17. 0.27, 0.44, 0.56, 0.65, 0.79, 0.98, 1.25, 1.56, 2.1, 2.42, 3.02, 3.6, 4.02]';

% The number of cars tested at each weight\
tested = [45 45 45 45 45 45 45 45 45 45 45 45 45 45]';

% The number of cars failing the test at each weight\
failed = [0 0 0 0 4 12 24 37 41 44 45 45 45 45]';

以下是我的设置:

在 MATLAB 中:

X = [tested failed]
y = log(weight)
[beta, std] = glmfit(y, X, 'binomial', 'link', 'probit');

结果:beta = [-0.6399, 3.2251]

在 Rstudio 中:

y <- log(weight) 
X <- cbind (tested, failed) 
model <-glm(X~y, family=binomial(link="probit"))

结果:summary(model) = [-0.905, 0.753]

结果明显不同,对于我来说,我似乎无法弄清楚为什么。任何帮助将不胜感激。

我猜你误读了文档:

Matlab:

% A set of car weights
x = [0.17, 0.27, 0.44, 0.56, 0.65, 0.79, 0.98, 1.25, 1.56, 2.1, 2.42, 3.02, 3.6, 4.02]';
% The number of cars tested at each weight
n = [45 45 45 45 45 45 45 45 45 45 45 45 45 45]';
% The number of cars failing the test at each weight
y = [0 0 0 0 4 12 24 37 41 44 45 45 45 45]';

x = log(x);
[beta, std] = glmfit(x,[y, n], 'binomial', 'link', 'probit')

% beta = [0.0574 3.2919]
% With glmfit(predictor,[passed tested]... 
% not  glmfit(predictor,[tested passed]...
% I'm even surprised that matlab output something else than an error.

R:

# A set of car weights
x <- c(0.17, 0.27, 0.44, 0.56, 0.65, 0.79, 0.98, 1.25, 1.56, 2.1, 2.42, 3.02, 3.6, 4.02);
# The number of cars tested at each weight
n <- c(45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45);
# The number of cars failing the test at each weight
y <- c(0, 0, 0, 0, 4, 12, 24, 37, 41, 44, 45, 45, 45, 45);

model <-glm(y/n~log(x), family=binomial(link="probit"),weights=n)

summary(model)

#Coefficients:
#            Estimate Std. Error z value Pr(>|z|)    
#(Intercept)  0.05736    0.09488   0.605    0.545    
#log(x)       3.29185    0.28049  11.736   <2e-16 ***

现在模型非常准确: