Skip to content

Instantly share code, notes, and snippets.

@jonesor
Created November 9, 2018 08:52
Show Gist options
  • Save jonesor/027f5bad3263e4dd2ffcadba72efd1fe to your computer and use it in GitHub Desktop.
Save jonesor/027f5bad3263e4dd2ffcadba72efd1fe to your computer and use it in GitHub Desktop.
Example of using an offset in a linear model
#offsets
#Simulate some data for this example
set.seed(12)
sig <- matrix(c(1.1,1,1,1.1),2,2)
df1<-data.frame(MASS::mvrnorm(n = 100, c(30,30), Sigma = sig ))
names(df1) <- c("x","y")
#Plot the data, and a 1:1 line
plot(df1$x,df1$y)
abline(0,1)
#Ordinary model with no offset.
#Slope summary gives statistics for difference from 0.
mod1 <- lm(y~x,data=df1)
summary(mod1)
#Ordinary model with no offset.
#Slope summary gives statistics for difference from 1.
mod2 <- lm(y~x+offset(x),data=df1)
summary(mod2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment