Created
November 9, 2018 08:52
-
-
Save jonesor/027f5bad3263e4dd2ffcadba72efd1fe to your computer and use it in GitHub Desktop.
Example of using an offset in a linear model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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