# What does the “1” in the R formula “y ~ 1” mean?

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.

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".

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)