Revision 92c36e33
Added by Benoit Parmentier over 12 years ago
- ID 92c36e334b16f2d8e77dce99fab4aeae1d442881
climate/research/oregon/interpolation/Linear_reg.R | ||
---|---|---|
7 | 7 |
|
8 | 8 |
###Loading r library and packages |
9 | 9 |
library(raster) # loading the raster package |
10 |
library(gtools) l# loading ...
|
|
10 |
library(gtools) # loading ...
|
|
11 | 11 |
library(sp) |
12 | 12 |
library(mgcv) |
13 | 13 |
|
... | ... | |
53 | 53 |
|
54 | 54 |
###Regression part 1: linear models |
55 | 55 |
|
56 |
lm_ANUSPLIN1=lm(tmax~lat+lon+ELEV_SRTM, data=ghcn1507_s)
|
|
57 |
lm_PRISM1=lm(tmax~lat+lon+ELEV_SRTM+ASPECT+DISTOC, data=ghcn1507_s) #Note that a variable on inversion is missing
|
|
56 |
lm_ANUSPLIN1<-lm(tmax~lat+lon+ELEV_SRTM, data=ghcn1507_s)
|
|
57 |
lm_PRISM1<-lm(tmax~lat+lon+ELEV_SRTM+ASPECT+DISTOC, data=ghcn1507_s) #Note that a variable on inversion is missing
|
|
58 | 58 |
summary(lm_ANUSPLIN1) |
59 | 59 |
summary(lm_PRISM1) |
60 | 60 |
|
61 | 61 |
###Regression part 2: GAM models |
62 |
GAM_PRISM1<-gam(tmax~ s(lat) + s (lon) + s (ELEV_SRTM), data=ghcn1507_s) |
|
63 | 62 |
GAM_ANUSPLIN1<-gam(tmax~ s(lat) + s (lon) + s (ELEV_SRTM), data=ghcn1507_s) |
63 |
GAM_PRISM1<-gam(tmax~ s(lat) + s (lon) + s (ELEV_SRTM) + s (ASPECT)+ s(DISTOC), data=ghcn1507_s) |
|
64 | 64 |
#use the s() for smoothing function |
65 | 65 |
|
66 | 66 |
###Compare the models |
... | ... | |
105 | 105 |
AIC_all<-AIC(lm_ANUSPLIN1,GAM_ANUSPLIN1,lm_PRISM1,GAM_PRISM1) |
106 | 106 |
results<-data.frame(model=mod_name,RMSE=RMSE_all,df=AIC_all$df,AIC=AIC_all$AIC) |
107 | 107 |
|
108 |
|
|
109 | 108 |
#dump("results", file= paste(path,"/","results_reg1507.txt",sep="")) |
110 | 109 |
write.csv(results, file= paste(path,"/","results_reg1507.txt",sep="")) |
111 | 110 |
|
Also available in: Unified diff
made minor changes to PRISM variables