Performs step-wise merging of factor levels.
mergeFactors(response, factor, ...)
response | A response |
---|---|
factor | A factor |
... | Other arguments corresponding to type of first argument |
rSample <- generateMultivariateSample(N = 100, k = 10, d = 3) rSample$covariates <- runif(100) rSample$weights <- runif(100) mergeFactors(response = rSample$response, factor = rSample$factor)#> Family: gaussian Factor Merger. #> Factor levels were recoded as below: #> #> |recoded |original | #> |:-------|:--------| #> |(J) |J | #> |(A) |A | #> |(E) |E | #> |(H) |H | #> |(I) |I | #> |(C) |C | #> |(D) |D | #> |(G) |G | #> |(F) |F | #> |(B) |B | #> #> Factor levels were merged in the following order: #> #> | |groupA |groupB | model| pvalVsFull| pvalVsPrevious| #> |:--|:---------------|:---------------|---------:|----------:|--------------:| #> |0 | | | -406.8129| 1.0000| 1.0000| #> |1 |(G) |(D) | -406.9139| 0.9809| 0.9809| #> |2 |(I) |(C) | -407.2632| 0.9918| 0.8906| #> |3 |(H) |(J) | -407.6956| 0.9963| 0.8536| #> |4 |(F) |(G)(D) | -408.1706| 0.9982| 0.8329| #> |5 |(B) |(F)(G)(D) | -409.2039| 0.9961| 0.5910| #> |6 |(I)(C) |(A) | -410.6091| 0.9902| 0.4527| #> |7 |(I)(C)(A) |(H)(J) | -412.2696| 0.9775| 0.3708| #> |8 |(E) |(B)(F)(G)(D) | -415.5644| 0.8746| 0.0982| #> |9 |(E)(B)(F)(G)(D) |(I)(C)(A)(H)(J) | -421.6679| 0.4341| 0.0082|mergeFactors(response = rSample$response, factor = rSample$factor, covariates = rSample$covariates)#> Family: gaussian Factor Merger. #> Factor levels were recoded as below: #> #> |recoded |original | #> |:-------|:--------| #> |(J) |J | #> |(A) |A | #> |(E) |E | #> |(H) |H | #> |(I) |I | #> |(C) |C | #> |(D) |D | #> |(G) |G | #> |(F) |F | #> |(B) |B | #> #> Factor levels were merged in the following order: #> #> | |groupA |groupB | model| pvalVsFull| pvalVsPrevious| #> |:--|:---------------|:---------------|---------:|----------:|--------------:| #> |0 | | | -404.2864| 1.0000| 1.0000| #> |1 |(G) |(D) | -404.4716| 0.9554| 0.9554| #> |2 |(I) |(C) | -404.8441| 0.9859| 0.8827| #> |3 |(F) |(G)(D) | -405.3472| 0.9928| 0.8253| #> |4 |(H) |(J) | -406.0264| 0.9944| 0.7460| #> |5 |(B) |(F)(G)(D) | -407.0716| 0.9916| 0.5907| #> |6 |(I)(C) |(A) | -408.3881| 0.9855| 0.4871| #> |7 |(I)(C)(A) |(H)(J) | -409.7609| 0.9784| 0.4633| #> |8 |(E) |(B)(F)(G)(D) | -413.2819| 0.8641| 0.0838| #> |9 |(E)(B)(F)(G)(D) |(I)(C)(A)(H)(J) | -421.6679| 0.3686| 0.0149|mergeFactors(rSample$response[,1], rSample$factor, covariates = rSample$covariates, weights = rSample$weights)#> Family: gaussian Factor Merger. #> Factor levels were recoded as below: #> #> |recoded |original | #> |:-------|:--------| #> |(J) |J | #> |(A) |A | #> |(E) |E | #> |(H) |H | #> |(I) |I | #> |(C) |C | #> |(D) |D | #> |(G) |G | #> |(F) |F | #> |(B) |B | #> #> Factor levels were merged in the following order: #> #> | |groupA |groupB | model| pvalVsFull| pvalVsPrevious| #> |:--|:---------|:---------------------|---------:|----------:|--------------:| #> |0 | | | -142.8948| 1.0000| 1.0000| #> |1 |(C) |(D) | -142.9527| 0.7489| 0.7489| #> |2 |(J) |(A) | -143.0196| 0.8949| 0.7293| #> |3 |(H) |(I) | -143.1665| 0.9219| 0.6062| #> |4 |(J)(A) |(E) | -143.3946| 0.9246| 0.5182| #> |5 |(F) |(B) | -143.6705| 0.9239| 0.4749| #> |6 |(C)(D) |(G) | -144.3241| 0.8570| 0.2689| #> |7 |(C)(D)(G) |(F)(B) | -144.6868| 0.8581| 0.4077| #> |8 |(H)(I) |(C)(D)(G)(F)(B) | -145.8920| 0.7017| 0.1292| #> |9 |(J)(A)(E) |(H)(I)(C)(D)(G)(F)(B) | -158.1114| 0.0016| 0.0000|dataset <- cbind(rSample$response, rSample$factor, rSample$covariates) colnames(dataset) <- c("res1","res2","res3","fct", "cov1") formula <- as.formula("res1+res2+res3~fct") formulaCovariates <-as.formula("res1+res2+res3~fct+cov1") mergeFactors(response = formula, factor="fct", data=dataset)#> Family: gaussian Factor Merger. #> Factor levels were recoded as below: #> #> |recoded |original | #> |:-------|:--------| #> |(1) |1 | #> |(2) |2 | #> |(3) |3 | #> |(4) |4 | #> |(5) |5 | #> |(6) |6 | #> |(7) |7 | #> |(8) |8 | #> |(9) |9 | #> |(10) |10 | #> #> Factor levels were merged in the following order: #> #> | |groupA |groupB | model| pvalVsFull| pvalVsPrevious| #> |:--|:----------------|:---------------|---------:|----------:|--------------:| #> |0 | | | -406.8129| 1.0000| 1.0000| #> |1 |(8) |(7) | -406.9139| 0.9809| 0.9809| #> |2 |(5) |(6) | -407.2632| 0.9918| 0.8906| #> |3 |(4) |(1) | -407.6956| 0.9963| 0.8536| #> |4 |(9) |(8)(7) | -408.1706| 0.9982| 0.8329| #> |5 |(10) |(9)(8)(7) | -409.2039| 0.9961| 0.5910| #> |6 |(5)(6) |(2) | -410.6091| 0.9902| 0.4527| #> |7 |(5)(6)(2) |(4)(1) | -412.2696| 0.9775| 0.3708| #> |8 |(3) |(10)(9)(8)(7) | -415.5644| 0.8746| 0.0982| #> |9 |(3)(10)(9)(8)(7) |(5)(6)(2)(4)(1) | -421.6679| 0.4341| 0.0082|mergeFactors(response = formulaCovariates, factor="fct", data=dataset)#> Family: gaussian Factor Merger. #> Factor levels were recoded as below: #> #> |recoded |original | #> |:-------|:--------| #> |(1) |1 | #> |(2) |2 | #> |(3) |3 | #> |(4) |4 | #> |(5) |5 | #> |(6) |6 | #> |(7) |7 | #> |(8) |8 | #> |(9) |9 | #> |(10) |10 | #> #> Factor levels were merged in the following order: #> #> | |groupA |groupB | model| pvalVsFull| pvalVsPrevious| #> |:--|:----------------|:---------------|---------:|----------:|--------------:| #> |0 | | | -404.2864| 1.0000| 1.0000| #> |1 |(8) |(7) | -404.4716| 0.9554| 0.9554| #> |2 |(5) |(6) | -404.8441| 0.9859| 0.8827| #> |3 |(9) |(8)(7) | -405.3472| 0.9928| 0.8253| #> |4 |(4) |(1) | -406.0264| 0.9944| 0.7460| #> |5 |(10) |(9)(8)(7) | -407.0716| 0.9916| 0.5907| #> |6 |(5)(6) |(2) | -408.3881| 0.9855| 0.4871| #> |7 |(5)(6)(2) |(4)(1) | -409.7609| 0.9784| 0.4633| #> |8 |(3) |(10)(9)(8)(7) | -413.2819| 0.8641| 0.0838| #> |9 |(3)(10)(9)(8)(7) |(5)(6)(2)(4)(1) | -421.6679| 0.3686| 0.0149|