3
$\begingroup$

I have data on the monthly rent of a certain group of people (n = 10 people). We call them people X. These people live in different neighborhoods (very far apart). Furthermore, I have data on the monthly rent of all other people in these neighborhoods. Let's call them people Y. The question is whether the people X have higher/lower rent than people Y.

enter image description here

However, neighborhoods are very different - with regard to the cost of housing. I do not feel right to take 10 rental people X values ​​and compare them to 250 people Y values ​​(eg using the Wilcoxon test). Rather, it seems to me that the right solution is to use a one-sample wilcoxon test separately for each neighborhood (comparing one value to 25 values 10 times). The problem, however, is that in some neighborhoods there is a statistical difference, in some not, and therefore I am not able to answer whether there is a general difference.

Is there any way to combine several single-sample tests into one test (or model) in order to obtain a general answer regarding the possible existence of a difference in rental rates between X and Y people?

# Example data:
my.data_X <- data.frame(id_neighborhood = 1:10,
                        rent = c(12,9,6,19,20,21,23,22,3,5))
my.data_X

set.seed(124)
my.data_Y <- data.frame(id_neighborhood = rep(c(1:10), each = 25),
                        rent = sample(c(6:30), 250, replace = TRUE))
head(my.data_Y)

# series of one-sample wilcoxon.test's
my.wilcox.p.val <- numeric(10)
for (i in 1:10) {
    my.wilcox.p.val[[i]] <- 
wilcox.test(my.data_Y$rent[my.data_Y$id_neighborhood == i],          
mu = my.data_X$rent[my.data_X$id_neighborhood == i],
alternative = "two.sided", correct = FALSE)$p.value
}
my.wilcox.p.val

my.results <- data.frame(id_neighborhood = 1:10,
rent_X = my.data_X$rent,
mean_rent_Y = tapply(my.data_Y$rent, my.data_Y$id_neighborhood, mean))
my.results$X_larger_than_Y <- my.results$rent_X > my.results$mean_rent_Y
my.results$p.val  <- round(my.wilcox.p.val, 3)

my.results

#    id_neighborhood rent_X mean_rent_Y X_larger_than_Y p.val
# 1                1     12       15.08           FALSE 0.088
# 2                2      9       17.56           FALSE 0.000
# 3                3      6       14.28           FALSE 0.000
# 4                4     19       18.84            TRUE 0.976
# 5                5     20       19.04            TRUE 0.396
# 6                6     21       17.28            TRUE 0.023
# 7                7     23       19.52            TRUE 0.033
# 8                8     22       16.12            TRUE 0.000
# 9                9      3       19.72           FALSE 0.000
# 10              10      5       16.32           FALSE 0.000

Here you can see, that in neighborhoods 2,3,9 and 10 is rent for people X lower than for people Y. Opposite can be found in neighborhoods 6,7,8. In neighborhoods 1,4,5 there is statistically no difference.

Does anybody know any other statistical approach how to obtain not partial answers, but generall answer? Is there any possibility to "merge" all those tests into single one, or use completely different strategy here?

$\endgroup$
1
  • $\begingroup$ I seems you are doing right-sided tests in some neighborhoods and left-sided tests in others. Also, you get significant results in some nbds and not in others. In many cities neighborhoods differ greatly (sizes, ages of houses, accessibility of parks, transportation, incomes, ethnicities of inhabitants). There may not be one single overall message in your data. But it may be worthwhile discussing circumstances in nbds with highly significant differences. $\endgroup$
    – BruceET
    Oct 4, 2019 at 5:05

1 Answer 1

3
+50
$\begingroup$

I think you may benefit from thinking more about your question.

You say that you are looking for a general answer comparing the rents of People X and Y, but go on to say that you also believe that a general answer is undesirable because there are important differences between neighborhoods.

So which is it? Do you ignore the effect of neighborhoods, and push for a "general" answer, or do you incorporate the effect of neighborhoods, and go for an answer that is "better"?

In my opinion: 1) You should have started with a "general" or "omnibus" test comparing the 10 X to the 250 Y. Based on those results, you might then go on to perform specific tests on different neighborhoods. Currently, you worked backwards: you ran multiple tests (with no adjustment for multiple comparisons such as a Bonferroni correction) and are now asking if you can aggregate back up. This is an odd question because a) neighborhoods either matter or they don't--if they do, why ignore them by taking a general approach? and b) If you found differences between neighborhoods, would you really believe a result that indicated no general difference? How could that be true, given what you've already learned?*

Also, you have some serious sample-size issues that may need to be looked at. You say that you ran ten different statistical tests comparing the median of a single (N=1) observation with N = 250 others? I strongly suggest enlisting the help of a statistician who is familiar with your data and research questions.

EDIT

I wanted to come back to address this question (and my response) because I did not fully understand your data at the time.

1) Although the data/example you've provided is helpful for people like me to understand the structure of your data, certain specific questions are unclear. For example, in your data you sample from a uniform distribution to create the rents in the "Y" population. Is this similar to the distribution in your actual data?

2) Supposing that your actual data are normally distributed (meaning a wilcoxon test is not needed), I though that the best way to illustrate an analysis like this would be to fit a linear model:

my.data_X <- data.frame(id_neighborhood = 1:10,
                    rent = c(12,9,6,19,20,21,23,22,3,5),
                    pop = "X")
set.seed(124)

my.data_Y <- data.frame(id_neighborhood = rep(c(1:10), each = 25),
                    rent = sample(c(6:30), 250, replace = TRUE),
                    pop = "Y")
#Combining the data from populations "X" and "Y"

my.data_all <- rbind.data.frame(my.data_X, my.data_Y)

# need to tell R to consider the neighborhood variable as a factor, rather than a true integer from 1:10

my.data_all$id_neighborhood <- factor(my.data_all$id_neighborhood)

#Fit a model and review the coefficients

summary(lm(rent ~ pop + id_neighborhood, data = my.data_all))

enter image description here

From the output of the model you can see that there is some evidence of a difference between the populations "X" and "Y" after accounting for the different neighborhoods. However, none of the 10 neighborhoods appears to have a significant effect on average rent. This is probably because 25 of the 26 data points from each neighborhood were randomly sampled from between 6-30.

Does something like this help point you in the direction you need? It's still unclear what you would like to show with your statistical analysis.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.