Project

General

Profile

« Previous | Next » 

Revision 45813eed

Added by Benoit Parmentier over 12 years ago

GWR, raster pred. modification model 8, function

View differences:

climate/research/oregon/interpolation/GWR_prediction_reg_function.R
51 51
    layerNames(s_raster_r)<-tab_range$varterm[k]
52 52
    val_rst[[k]]<-s_raster_r
53 53
  }
54
  s_rst_m<-stack(val_rst) #This a stacked with valid range of values
54
  s_rst_m<-stack(val_rst) #This a raster stack with valid range of values
55 55
  
56 56
  ###Regression part 1: Creating a validation dataset by creating training and testing datasets
57 57
  
58 58
  mod_LST <-ghcn.subsets[[i]][,match(LST_month, names(ghcn.subsets[[i]]))]  #Match interpolation date and monthly LST average
59
  ghcn.subsets[[i]] = transform(ghcn.subsets[[i]],LST = mod_LST)            #Add the variable LST to the subset dataset
59
  ghcn.subsets[[i]] <- transform(ghcn.subsets[[i]],LST = mod_LST)            #Add the variable LST to the subset dataset
60 60
  #n<-nrow(ghcn.subsets[[i]])
61 61
  #ns<-n-round(n*prop)   #Create a sample from the data frame with 70% of the rows
62 62
  #nv<-n-ns              #create a sample for validation with prop of the rows
......
101 101
  formula5 <- as.formula("y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST", env=.GlobalEnv)
102 102
  formula6 <- as.formula("y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST + LC1", env=.GlobalEnv)
103 103
  formula7 <- as.formula("y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST + LC3", env=.GlobalEnv)
104
  formula8 <- as.formula("y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST + I(LC1*LC3)", env=.GlobalEnv)
104
  formula8 <- as.formula("y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST + I(LST*LC1)", env=.GlobalEnv)
105 105
  
106 106
  #   bwG <- gwr.sel(tmax~ lon + lat + ELEV_SRTM + Eastness + Northness + DISTOC,data=data_s,gweight=gwr.Gauss, verbose = FALSE)
107 107
  #   gwrG<- gwr(tmax~ lon + lat + ELEV_SRTM + Eastness + Northness + DISTOC, data=data_s, bandwidth=bwG, gweight=gwr.Gauss, hatmatrix=TRUE)
......
168 168
      mod_varn<-t_l
169 169
    }
170 170
    #browser()
171
    mod_varn <-unique(mod_varn)
171 172
    list_rst<-vector("list",length(mod_varn))
172 173
    pos<-match(mod_varn,layerNames(s_rst_m)) #Find column with the current month for instance mm12 
173 174
    s_rst_mod<-subset(s_rst_m,pos)
......
181 182
    coordinates(s_spdf)<-coords
182 183
    proj4string(s_spdf)<-CRS  #Need to assign coordinates...
183 184
    
184

  
185 185
    #If mod "j" is not a model object
186 186
    if (inherits(mod,"try-error")) {
187 187
      
......
234 234
    #If mod "j" is not a model object
235 235
    if (inherits(mod,"gwr")) {
236 236
      
237
      pred <- gwr(formula1, data_s, bandwidth=bwGm, fit.points =s_spdf,predict=TRUE, se.fit=TRUE,fittedGWRobject=mod)
237
      pred <- gwr(formula, data_s, bandwidth=bwGm, fit.points =s_spdf,predict=TRUE, se.fit=TRUE,fittedGWRobject=mod)
238
      #pred <- try(gwr(formula, data_s, bandwidth=bwGm, fit.points =s_spdf,predict=TRUE, se.fit=TRUE,fittedGWRobject=mod))
238 239
      
239 240
      pred_gwr[[j]]<-pred   #prediction stored in a list
240 241
      

Also available in: Unified diff