How to extract proper Terms naming from SO Anova surrogate model ?

###################################################

to help (I hope !) a report is generated (sink(...)) to condense output of interest

as well as some environnement infos from "sessionInfo()", etc..

################################################## script Starts
library(reprex)
#> Warning: le package 'reprex' a t compil avec la version R 3.5.1
library(Rgraphviz)
#> Warning: le package 'Rgraphviz' a t compil avec la version R 3.5.1
#> Le chargement a ncessit le package : graph
#> Warning: le package 'graph' a t compil avec la version R 3.5.1
#> Le chargement a ncessit le package : BiocGenerics
#> Warning: le package 'BiocGenerics' a t compil avec la version R 3.5.1
#> Le chargement a ncessit le package : parallel
#>
#> Attachement du package : 'BiocGenerics'
#> The following objects are masked from 'package:parallel':
#>
#> clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
#> clusterExport, clusterMap, parApply, parCapply, parLapply,
#> parLapplyLB, parRapply, parSapply, parSapplyLB
#> The following objects are masked from 'package:stats':
#>
#> IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#>
#> anyDuplicated, append, as.data.frame, basename, cbind,
#> colMeans, colnames, colSums, dirname, do.call, duplicated,
#> eval, evalq, Filter, Find, get, grep, grepl, intersect,
#> is.unsorted, lapply, lengths, Map, mapply, match, mget, order,
#> paste, pmax, pmax.int, pmin, pmin.int, Position, rank, rbind,
#> Reduce, rowMeans, rownames, rowSums, sapply, setdiff, sort,
#> table, tapply, union, unique, unsplit, which, which.max,
#> which.min
#> Le chargement a ncessit le package : grid
library(knitr)
#> Warning: le package 'knitr' a t compil avec la version R 3.5.1
library(rsm)
#> Warning: le package 'rsm' a t compil avec la version R 3.5.1
library(yaml)
#> Warning: le package 'yaml' a t compil avec la version R 3.5.1
library(broom)
#> Warning: le package 'broom' a t compil avec la version R 3.5.2
library(ggplot2)
#> Warning: le package 'ggplot2' a t compil avec la version R 3.5.2

Input Data

setwd("D:\Session_R\WaterBox\Anova")
Donnees<-read.csv("..\Excel_vers_R\Example_SO.csv",sep=" ",header=TRUE)
attach(Donnees)
Report <- paste("Ex_naming_SO_model",".txt",sep="") # Routing output to a Report file : Could help....!
sink(Report,append=TRUE) # In order to visualize the different Terms naming obtained
Sys.Date()
#> [1] "2019-05-22"
cat("\n======== Attempt to improve the Terms Naming of Anova Polynomial=================\n\n")
#>
#> ======== Attempt to improve the Terms Naming of Anova Polynomial=================
cat("==============Input file: ",Entree,"\n")
#> Error in cat("==============Input file: ", Entree, "\n"): objet 'Entree' introuvable
packageStatus()
#> Number of installed packages:
#>
#> ok upgrade unavailable
#> C:/Users/gbesombe/Documents/R/win-library/3.5 78 51 4
#> C:/Program Files/R/R-3.5.0/library 17 12 1
#>
#> Number of available packages (each package counted only once):
#>
#> installed not installed
#> https://cran.rstudio.com/src/contrib 144 14067
#> https://cloud.r-project.org/src/contrib 0 0
R.Version()$platform
#> [1] "x86_64-w64-mingw32"
R.Version()$version.string
#> [1] "R version 3.5.0 (2018-04-23)"
sessionInfo()
#> R version 3.5.0 (2018-04-23)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 17763)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
#> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
#> [5] LC_TIME=French_France.1252
#>
#> attached base packages:
#> [1] grid parallel stats graphics grDevices utils datasets
#> [8] methods base
#>
#> other attached packages:
#> [1] ggplot2_3.1.0 broom_0.5.1 yaml_2.2.0
#> [4] rsm_2.10 knitr_1.20 Rgraphviz_2.26.0
#> [7] graph_1.60.0 BiocGenerics_0.28.0 reprex_0.2.1
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.0 plyr_1.8.4 compiler_3.5.0 pillar_1.3.0
#> [5] bindr_0.1.1 tools_3.5.0 digest_0.6.18 gtable_0.2.0
#> [9] evaluate_0.12 tibble_1.4.2 nlme_3.1-137 lattice_0.20-35
#> [13] pkgconfig_2.0.2 rlang_0.3.0.1 bindrcpp_0.2.2 withr_2.1.2
#> [17] dplyr_0.7.8 stringr_1.3.1 generics_0.0.2 fs_1.2.6
#> [21] stats4_3.5.0 rprojroot_1.3-2 tidyselect_0.2.5 glue_1.3.0
#> [25] R6_2.3.0 rmarkdown_1.10 purrr_0.2.5 tidyr_0.8.2
#> [29] magrittr_1.5 scales_1.0.0 backports_1.1.2 htmltools_0.3.6
#> [33] assertthat_0.2.0 colorspace_1.4-0 stringi_1.2.4 lazyeval_0.2.1
#> [37] munsell_0.5.0 crayon_1.3.4
#########
cat("\n===== Anova process \n")
#>
#> ===== Anova process

y_SO=aov(Donnees[,8] ~ SO(H1,H2,H3,H4,H5)) # The terms naming are awfull
anov_SO=anova(y_SO) # same but naming could be better from that !
anovSO <- broom::tidy(anov_SO) # to compare "Broom" output with direct "anova"
#> Warning: le package 'bindrcpp' a t compil avec la version R 3.5.1
rsm_SO <- rsm(Donnees[,8] ~ SO(H1,H2,H3,H4,H5),data = Donnees)# inactiv if there are Aliases
cat("\n Quadratic Model Estimators <<<<<<<<<<<<<<<<< Distrib >>>>>>>>>>>>>>>>>>> : \n")
#>
#> Quadratic Model Estimators <<<<<<<<<<<<<<<<< Distrib >>>>>>>>>>>>>>>>>>> :
print(y_SO$call) ;print(y_SO$coeff)
#> aov(formula = Donnees[, 8] ~ SO(H1, H2, H3, H4, H5))
#> (Intercept) SO(H1, H2, H3, H4, H5)H1
#> 1.914675e+00 -2.940533e-03
#> SO(H1, H2, H3, H4, H5)H2 SO(H1, H2, H3, H4, H5)H3
#> 1.085412e-02 -6.474844e-02
#> SO(H1, H2, H3, H4, H5)H4 SO(H1, H2, H3, H4, H5)H5
#> -3.954216e-02 -1.325946e-03
#> SO(H1, H2, H3, H4, H5)H1:H2 SO(H1, H2, H3, H4, H5)H1:H3
#> -5.086009e-06 5.635323e-05
#> SO(H1, H2, H3, H4, H5)H1:H4 SO(H1, H2, H3, H4, H5)H1:H5
#> 3.716821e-05 -3.378597e-06
#> SO(H1, H2, H3, H4, H5)H2:H3 SO(H1, H2, H3, H4, H5)H2:H4
#> -7.946072e-04 -1.700036e-04
#> SO(H1, H2, H3, H4, H5)H2:H5 SO(H1, H2, H3, H4, H5)H3:H4
#> 3.003183e-05 3.336399e-04
#> SO(H1, H2, H3, H4, H5)H3:H5 SO(H1, H2, H3, H4, H5)H4:H5
#> -9.591206e-05 3.611922e-05
#> SO(H1, H2, H3, H4, H5)H1^2 SO(H1, H2, H3, H4, H5)H2^2
#> 5.689683e-06 2.380932e-04
#> SO(H1, H2, H3, H4, H5)H3^2 SO(H1, H2, H3, H4, H5)H4^2
#> 1.358376e-03 5.369260e-04
#> SO(H1, H2, H3, H4, H5)H5^2
#> 4.827157e-05

cat(" >> Problem submited by Gilles. Besombes : Valeo Group\n")
#> >> Problem submited by Gilles. Besombes : Valeo Group
cat("Purpose : Getting proper naming of the polynomial terms from Anova estimators")
#> Purpose : Getting proper naming of the polynomial terms from Anova estimators
cat(" Problem : The resulting Terms naming above like (H1,H2...)H1^2 instead of H1^2
is extremely unconfortable for SO model. This makes impossible to plot any hierarchy...")
#> Problem : The resulting Terms naming above like (H1,H2...)H1^2 instead of H1^2
#> is extremely unconfortable for SO model. This makes impossible to plot any hierarchy...
cat("\n Question: How to extract proper names Terms of the SO polynomial from Anova process ?")
#>
#> Question: How to extract proper names Terms of the SO polynomial from Anova process ?
cat("\n The example is with SO, but could be extended to 2FI, PG, Cubic, etc...
It would be also very usefull not to be obliged to specify all the terms by hand but rather automatically
from the number of parameters specified in a variable, for example:
Nbparam=5 means to build a SO polynomial with the 5 first names from input CSV\n")
#>
#> The example is with SO, but could be extended to 2FI, PG, Cubic, etc...
#> It would be also very usefull not to be obliged to specify all the terms by hand but rather automatically
#> from the number of parameters specified in a variable, for example:
#> Nbparam=5 means to build a SO polynomial with the 5 first names from input CSV

cat(" >>>> Thanks a lot for any possible ideas....")
#> >>>> Thanks a lot for any possible ideas....

cat("\n\n============== End of script ==============")
#>
#>
#> ============== End of script ==============
sink()

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.