[R] library(nlme) groupedData question‏

Andre Mikulec andre_mikulec at hotmail.com
Mon Oct 19 14:31:04 CEST 2015



All,

Some trial and error follows ( for anyone who cares ).


The case seems that groupedData does not like 
to have both "a grouping" and "an outher" defined at the same time.


library(nlme)


d.x <- read.table(header=TRUE, text="
o g h i     d
A C E G     1.0
A C E H     2
A C F G     4
A C F H     8

A D E G     16
A D E H     32
A D F G     64
A D F H     128

B C E G     256
B C E H     1024
B C F G     2048
B C F H     4096

B D E G     8192
B D E H     16384
B D F G     32768
B D F H     65536
", stringsAsFactors = FALSE)


# desirable 'outer' ommitted ( but I want 'outer' )


gd <- groupedData(formula = d ~ h | g  
                  , data  = d.x 
                  , inner = ~ i
)


# best (available) solution


gd <- groupedData(formula = d ~ h | o/g
                  , data  = d.x 
                  , inner = ~ i
)


> str(gd, vec.len = 16)
Classes 'nmGroupedData', 'groupedData' and 'data.frame':        16 obs. of  5 variables:
 $ o: chr  "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B" "B" "B" "B" "B" "B"
 $ g: chr  "C" "C" "C" "C" "D" "D" "D" "D" "C" "C" "C" "C" "D" "D" "D" "D"
 $ h: chr  "E" "E" "F" "F" "E" "E" "F" "F" "E" "E" "F" "F" "E" "E" "F" "F"
 $ i: chr  "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H"
 $ d: num  1 2 4 8 16 32 64 128 256 1024 2048 4096 8192 16384 32768 65536
 - attr(*, "formula")=Class 'formula' length 3 d ~ h | o/g
  .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
 - attr(*, "formulaList")=List of 2
  ..$ o:Class 'formula' length 2 ~o
  .. .. ..- attr(*, ".Environment")=<environment: 0x00000000062a2a78>
  ..$ g:Class 'formula' length 2 ~g
  .. .. ..- attr(*, ".Environment")=<environment: 0x00000000062a3fa8>
 - attr(*, "inner")=List of 1
  ..$ g:Class 'formula' length 2 ~i
  .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
 - attr(*, "order.groups")=List of 2
  ..$ o: logi TRUE
  ..$ g: logi TRUE
 - attr(*, "FUN")=function (x)




Andre Mikulec
Andre_Mikulec at Hotmail.com


----------------------------------------
> From: andre_mikulec at hotmail.com
> To: r-help at r-project.org
> Subject: library(nlme) groupedData question‏
> Date: Mon, 12 Oct 2015 08:53:53 -0400
>
>
> SUMMARY
> -------
>
> Using package nlme, I am getting the following warning
> when I try to create a grouped data object using groupedData().
>
> I believe that my logic is faulty.
>
> Warning message:
> In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
> duplicated levels in factors are deprecated
>
> What am I doing wrong? How do I adjust?
>
> Thanks,
> Andre Mikulec
> Andre_Mikulec at Hotmail.com
>
>
> DETAILS ( the following R code can be copied and pasted to the R console and ran )
> -------
>
> library(nlme)
>
> d.x <- read.table(header=TRUE, text="
> o g h i d
> A C E G 1.0
> A C E H 2
> A C F G 4
> A C F H 8
>
> A D E G 16
> A D E H 32
> A D F G 64
> A D F H 128
>
> B C E G 256
> B C E H 1024
> B C F G 2048
> B C F H 4096
>
> B D E G 8192
> B D E H 16384
> B D F G 32768
> B D F H 65536
> ", stringsAsFactors = FALSE)
>
> str(d.x, vec.len = 16)
> # 'data.frame': 16 obs. of 5 variables:
> # $ o: chr "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B" "B" "B" "B" "B" "B"
> # $ g: chr "C" "C" "C" "C" "D" "D" "D" "D" "C" "C" "C" "C" "D" "D" "D" "D"
> # $ h: chr "E" "E" "F" "F" "E" "E" "F" "F" "E" "E" "F" "F" "E" "E" "F" "F"
> # $ i: chr "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H"
> # $ d: num 1 2 4 8 16 32 64 128 256 1024 2048 4096 8192 16384 32768 65536
>
> gd <- groupedData(formula = d ~ h | g
> , data = d.x
> , outer = ~ o
> , inner = ~ i
> )
>
> # Warning message:
> # In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
> # duplicated levels in factors are deprecated
>
>
> str(gd, vec.len = 16)
> # Classes 'nffGroupedData', 'nfGroupedData', 'groupedData' and 'data.frame': 16 obs. of 5 variables:
> # $ o: chr "A" "A" "A" "A" "A" "A" "A" "A" "B" "B" "B" "B" "B" "B" "B" "B"
> # $ g: Ord.factor w/ 4 levels "C"<"D"<"C"<"D": 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2
> # $ h: chr "E" "E" "F" "F" "E" "E" "F" "F" "E" "E" "F" "F" "E" "E" "F" "F"
> # $ i: chr "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H" "G" "H"
> # $ d: num 1 2 4 8 16 32 64 128 256 1024 2048 4096 8192 16384 32768 65536
> # - attr(*, "formula")=Class 'formula' length 3 d ~ h | g
> # .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
> # - attr(*, "outer")=Class 'formula' length 2 ~o
> # .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
> # - attr(*, "inner")=Class 'formula' length 2 ~i
> # .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
> # - attr(*, "FUN")=function (x)
> # - attr(*, "order.groups")= logi TRUE
>
>
> SOFTWARE INFORMATION
> ----------------
>
>> sessionInfo()
> R version 3.2.2 (2015-08-14)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] nlme_3.1-121
>
> loaded via a namespace (and not attached):
> [1] grid_3.2.2 lattice_0.20-33
>
>
>
> Thanks,
>
> Andre Mikulec
> Andre_Mikulec at Hotmail.com 		 	   		  


More information about the R-help mailing list