modelFit is used to fit a metamodel of class lm, gam,
mars, polymars or km.
Usage
modelFit (X,Y, type, ...)
Arguments
X
a data.frame containing the design of experiments
Y
a vector containing the response variable
type
represents the method used to fit the model:
"Linear"
linear model,
"StepLinear"
stepwise,
"Additive"
gam,
"MARS"
mars
"PolyMARS"
polymars
"Kriging"
kriging model.
...
corresponds to the parameter(s) of the model. The list of the needed arguments for each type of models is given below:
"Linear"
formula (see formulaLm),
"StepLinear"
formula
penalty parameter,
"Additive"
formula (see formulaAm),
"MARS"
degree,
"PolyMARS"
gcv criteria.
"Kriging"
formula
covtype
Value
A list with the following components:
X
a data frame representing the design of experiments
Y
a vector representing the response
type
the type of metamodel
model
a fitted model of the specified class
and the value of the parameter(s) depending on the fitted model.
Author(s)
D. Dupuy
See Also
modelPredict
Examples
# A 2D example
Branin <- function(x1,x2) {
x1 <- x1*15-5
x2 <- x2*15
(x2 - 5/(4*pi^2)*(x1^2) + 5/pi*x1 - 6)^2 + 10*(1 - 1/(8*pi))*cos(x1) + 10
}
# a 2D uniform design and the value of the response at these points
X <- matrix(runif(24),ncol=2,nrow=12)
Z <- Branin(X[,1],X[,2])
Y <- (Z-mean(Z))/sd(Z)
# construction of a linear model
modLm <- modelFit(X,Y,type = "Linear",formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))
summary(modLm$model)
## Not run:
# construction of a stepwise-selected model
modStep <- modelFit(X,Y,type = "StepLinear",penalty=log(dim(X)[1]),
formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))
summary(modStep$model)
# construction of an additive model
library(gam)
modAm <- modelFit(X,Y,type = "Additive",formula=Y~s(X1)+s(X2))
summary(modAm$model)
# construction of a MARS model of degree 2
library(mda)
modMARS <- modelFit(X,Y,type = "MARS",degree=2)
print(modMARS$model)
# construction of a PolyMARS model with a penalty parameter equal to 1
library(polspline)
modPolyMARS <- modelFit(X,Y,type = "PolyMARS",gcv=1)
summary(modPolyMARS$model)
# construction of a Kriging model
modKm <- modelFit(X,Y,type = "Kriging")
str(modKm$model)
## End(Not run)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(DiceEval)
Loading required package: DiceKriging
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DiceEval/modelFit.Rd_%03d_medium.png", width=480, height=480)
> ### Name: modelFit
> ### Title: Fitting metamodels
> ### Aliases: modelFit
> ### Keywords: models
>
> ### ** Examples
>
> # A 2D example
> Branin <- function(x1,x2) {
+ x1 <- x1*15-5
+ x2 <- x2*15
+ (x2 - 5/(4*pi^2)*(x1^2) + 5/pi*x1 - 6)^2 + 10*(1 - 1/(8*pi))*cos(x1) + 10
+ }
> # a 2D uniform design and the value of the response at these points
> X <- matrix(runif(24),ncol=2,nrow=12)
> Z <- Branin(X[,1],X[,2])
> Y <- (Z-mean(Z))/sd(Z)
>
> # construction of a linear model
> modLm <- modelFit(X,Y,type = "Linear",formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))
> summary(modLm$model)
Call:
lm(formula = fmla, data = data)
Residuals:
Min 1Q Median 3Q Max
-0.237530 -0.093927 0.003293 0.045156 0.261372
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.2297 0.7406 -1.660 0.1479
X1 0.9225 2.0161 0.458 0.6634
X2 -0.6638 1.4531 -0.457 0.6639
I(X1^2) -0.8991 1.4373 -0.626 0.5546
I(X2^2) 1.4036 1.4143 0.992 0.3593
X1:X2 2.9662 1.0640 2.788 0.0317 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1986 on 6 degrees of freedom
Multiple R-squared: 0.9785, Adjusted R-squared: 0.9606
F-statistic: 54.6 on 5 and 6 DF, p-value: 6.37e-05
>
> ## Not run:
> ##D # construction of a stepwise-selected model
> ##D modStep <- modelFit(X,Y,type = "StepLinear",penalty=log(dim(X)[1]),
> ##D formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))
> ##D summary(modStep$model)
> ##D
> ##D # construction of an additive model
> ##D library(gam)
> ##D modAm <- modelFit(X,Y,type = "Additive",formula=Y~s(X1)+s(X2))
> ##D summary(modAm$model)
> ##D
> ##D # construction of a MARS model of degree 2
> ##D library(mda)
> ##D modMARS <- modelFit(X,Y,type = "MARS",degree=2)
> ##D print(modMARS$model)
> ##D
> ##D # construction of a PolyMARS model with a penalty parameter equal to 1
> ##D library(polspline)
> ##D modPolyMARS <- modelFit(X,Y,type = "PolyMARS",gcv=1)
> ##D summary(modPolyMARS$model)
> ##D
> ##D # construction of a Kriging model
> ##D modKm <- modelFit(X,Y,type = "Kriging")
> ##D str(modKm$model)
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>