6
$\begingroup$

I am trying to understand the code written in the following discussion (see link):

library(boot) 
library(reshape) 
dataset <- data.frame(Person = c(rep("A", 20), rep("B", 10)), Success = c(rbinom(20, 1, 0.25), rbinom(10, 1, 0.75))) 
Aggregated <- cast(Person ~ ., data = dataset, value = "Success", fun = list(mean, length)) 

m0 <- glm(Success ~ 1, data = dataset, family = binomial) 
m1 <- glm(mean ~ 1, data = Aggregated, family = binomial, weights = length) 

inv.logit(coef(m0)) 
inv.logit(coef(m1)) 

I am confused as to what the 1 in the formula Success ~ 1 means. In the documentation for the formula, there is a description of the special symbol . in a formula but there is not description of 1, except that y ~ x - 1 means a line through the origin.

$\endgroup$
7
$\begingroup$

In most R regression packages, y ~ 1 means "fit an intercept only".

So in the case of linear regression, this is exactly the same as mean(y). For glm's, it depends on the link function.

Also, y ~ x - 1 means "regress x on y, but leave out the intercept".

$\endgroup$
1
$\begingroup$

That means intercept only model. You can use model.matrix to find out. Try the following codes:

library(boot) 
library(reshape) 
dataset <- data.frame(Person = c(rep("A", 20), rep("B", 10)), Success = c(rbinom(20, 1, 0.25), rbinom(10, 1, 0.75))) 
Aggregated <- cast(Person ~ ., data = dataset, value = "Success", fun = list(mean, length)) 

m0 <- glm(Success ~ 1, data = dataset, family = binomial) 
model.matrix(Success ~ 1, data = dataset)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.