svyboxplot duplicates results (survey package)

Hello everyone,

I am new to the survey package and using it to do very simple data visualization. I have simple random sample data (I think? Just the weights are known), where I have made data weights using anesrake package and then created a survey design using the following code:
my_des <- svydesign(data = kysely_hirvi, weights = ~weight, ids = ~1)

I have a weird problem considering the svyboxplot, when I use the following code:
b <- svyboxplot(hirvi_sarvisuositus~factor(riistakeskus), my_des, all.outliers = F)
It draws all the categories identical : exactly same values for each grouping category, which is not true. I have a feeling that it is possibly the last category, which is somehow duplicated for every category?

When I studied the problem subsetting each of my category (15 of them) using the following code:
svyboxplot(hirvi_sarvisuositus~1, subset(my_des, riistakeskus == "Etelä-Häme"), ylim = c(0,10))
the values are different for each area / different boxplots for each area.

Can anyone help me? I am desperate!

PS. Here`s sample to test

library(tidyverse)

col <- tibble(
name = c("seura 1", "seura 2", "seura 3", "seura 4", "seura 5", "seura 6", "seura 7", "seura 8", "seura 9"
, "seura 10", "seura 11", "seura 12"),
riistakeskus = c("Keski-Suomi","Keski-Suomi","Keski-Suomi","Keski-Suomi","Keski-Suomi","Satakunta","Satakunta",
"Satakunta","Uusimaa", "Uusimaa","Uusimaa","Uusimaa"),
hirvi_sarvisuositus = c(1,4,5,3,7,5,3,4,6,5,8,9),
weights = c(1.1461438,1.1461438,1.1461438,1.1461438,1.1461438,0.5107815,0.5107815,0.5107815,2.0461937,
2.0461937,2.0461937,2.0461937)
)

library(survey)
my_des1 <- svydesign(data = col, weights = ~weights, ids = ~1)
b <- svyboxplot(hirvi_sarvisuositus~factor(riistakeskus), my_des1, all.outliers = F, ylim = c(0,10))
svyboxplot(hirvi_sarvisuositus~1, subset(my_des1, riistakeskus == "Keski-Suomi"), ylim = c(0,10))
svyboxplot(hirvi_sarvisuositus~1, subset(my_des1, riistakeskus == "Satakunta"), ylim = c(0,10))
svyboxplot(hirvi_sarvisuositus~1, subset(my_des1, riistakeskus == "Uusimaa"), ylim = c(0,10))

I think this is a bug. I tried to make a simpler example where the weights are all 1 and this doesn't work still.

library(tidyverse)

mycol <- tibble(
   name = c("seura 1", "seura 2", "seura 3", "seura 4", "seura 5", "seura 6", "seura 7", "seura 8", "seura 9"
            , "seura 10", "seura 11", "seura 12"),
   riistakeskus = c("Keski-Suomi","Keski-Suomi","Keski-Suomi","Keski-Suomi","Keski-Suomi","Satakunta","Satakunta",
                    "Satakunta","Uusimaa", "Uusimaa","Uusimaa","Uusimaa"),
   hirvi_sarvisuositus = c(1,4,5,3,7,5,3,4,6,5,8,9),
   # weights = c(1.1461438,1.1461438,1.1461438,1.1461438,1.1461438,0.5107815,0.5107815,0.5107815,2.0461937,
   #             2.0461937,2.0461937,2.0461937)
   weights=1
) %>%
   mutate(riistakeskus=as.factor(riistakeskus)) %>%
   as.data.frame()

mycol
#>        name riistakeskus hirvi_sarvisuositus weights
#> 1   seura 1  Keski-Suomi                   1       1
#> 2   seura 2  Keski-Suomi                   4       1
#> 3   seura 3  Keski-Suomi                   5       1
#> 4   seura 4  Keski-Suomi                   3       1
#> 5   seura 5  Keski-Suomi                   7       1
#> 6   seura 6    Satakunta                   5       1
#> 7   seura 7    Satakunta                   3       1
#> 8   seura 8    Satakunta                   4       1
#> 9   seura 9      Uusimaa                   6       1
#> 10 seura 10      Uusimaa                   5       1
#> 11 seura 11      Uusimaa                   8       1
#> 12 seura 12      Uusimaa                   9       1

library(survey)
#> Loading required package: grid
#> Loading required package: Matrix
#> 
#> Attaching package: 'Matrix'
#> The following objects are masked from 'package:tidyr':
#> 
#>     expand, pack, unpack
#> Loading required package: survival
#> 
#> Attaching package: 'survey'
#> The following object is masked from 'package:graphics':
#> 
#>     dotchart
my_des1 <- svydesign(data = mycol, weights = ~weights, ids = ~1)
svyboxplot(hirvi_sarvisuositus~riistakeskus, my_des1, all.outliers = TRUE)

boxplot(hirvi_sarvisuositus~riistakeskus, mycol)

Created on 2021-10-22 by the reprex package (v2.0.1)

Yep, I agree. I have been playing with the weights little bit and I also end up with the same results. Too bad..

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.