Created
April 25, 2016 17:21
-
-
Save primaryobjects/ffd15803240a3ab7535a32487724d458 to your computer and use it in GitHub Desktop.
Climate change dataset analysis, using linear regression.
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
| data <- read.csv('climate_change.csv') | |
| train <- subset(data, Year <= 2006) | |
| test <- subset(data, Year > 2006) | |
| fit <- lm(Temp ~ MEI + CO2 + CH4 + N2O + CFC.11 + CFC.12 + TSI + Aerosols, data=train) | |
| fit2 <- lm(Temp ~ MEI + TSI + Aerosols + N2O, data=train) | |
| # Auto-create model (note, step does not address the collinearity of the variables, so some features removed in fit2 are present in this model). | |
| fit3 <- step(fit) | |
| pred <- predict(fit3, newdata=test) | |
| SSE <- sum((pred - test$Temp)^2) | |
| SST <- sum((mean(train$Temp) - test$Temp)^2) | |
| R2 <- 1 - SSE/SST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment