Created
February 15, 2016 17:48
-
-
Save timcdlucas/4c44c0b4fe59592d385a to your computer and use it in GitHub Desktop.
Compare slopes bewteen two datasets.
This file contains hidden or 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
# Make up some data | |
data1 <- data.frame(length = rnorm(20, 8), weight = 1:20) | |
data2 <- data.frame(length = rnorm(30, 8), weight = 1:30) | |
# add a dummy variable and combine the data | |
data1$dummy <- 'data1' | |
data2$dummy <- 'data2' | |
combinedData <- rbind(data1, data2) | |
# Fit model that ignores the different data sets | |
model1 <- lm(length ~ weight, data = combinedData) | |
# Now fit an interaction between the dummy and the slope and coeficients. | |
model2 <- lm(length ~ dummy*weight, data = combinedData) | |
library(lmtest) | |
lrtest(model1, model2) | |
# If you wanted to ONLY compare the slopes you could do | |
model3 <- lm(length ~ weight + dummy:weight, data = combinedData) | |
lrtest(model1, model3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment