weiA2Ens: Ensemble Weighted Prediction of Mixed Models

Description Usage Arguments Value Author(s) Examples

View source: R/weiA2Ens.R

Description

Weighted average and standard deviation of multiple models. The weights can be the model's performance metrics such as R2 or RMSE.

Usage

1
weiA2Ens(pPath,mFile,metrF="rmse",preF="pre",idF="gid",dateF=NA)

Arguments

pPath

Path for the prediction files from multiple models with the unified format and field names. File format: CSV with head.

mFile

File path for the corresponding multiple models's performance. CSV format:mid, r2, rmse.

metrF

target metric such as rmse or r2 to weigh the model's output

preF

prediction field name

idF

unique identifier string

dateF

date string if any

Value

id and corresponding mean and standard deviation. Format: dataframe

Author(s)

Lianfa Li: lspatial@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#First generate the prediction dataset and metrics.
# In application, you can use parSpModel to train models and
# get the models's performance metrics, and use the parATimePredict function to make the prediction

# Simulared data

dPath=tempdir()
pPath=paste(dPath,"/preds",sep="")
unlink(pPath, recursive=TRUE, force=TRUE)
dir.create(pPath)

nr=2000;nmod=80
for(i in c(1:nmod)){ # i =1
  dset=data.frame(gid=c(1:nr),rid=sample(c(1:30),size=nr,replace=TRUE),stringsAsFactors = FALSE)
  dset$pre=dset$gid%%nmod+rnorm(nr,mean=5,sd=9)+runif(nr,0,1)
  dset$gid=paste("c",dset$gid,sep="")
  afile=paste(pPath,"/m",i,".csv",sep="")
  write.csv(dset,file=afile,row.names = FALSE)
}

modelsMetrics=data.frame(mid=c(1:nmod),r2=runif(nmod,0.6,0.9),rmse=runif(nmod,20,60))
mfile=paste(dPath,"/model_metrics.csv",sep="")
write.csv(modelsMetrics,file=mfile,row.names = FALSE)
result=weiA2Ens(pPath,mfile,metrF="rmse","pre","gid","gid")

lspatial/sptemUS documentation built on May 29, 2019, 3:42 a.m.