1
$\begingroup$

I have two variables age and type of car bought.

Age is in groups. Eg.

$<25$, $26-35$, $36-45$, $46-55$, $>55$.

Car is 1. American, 2. Japanese, 3. European

It seems like a simple Chi Square to test relationship, but there is more than 2 categories?

Does this mean I have to use a One Anova test? How can I do this without a continuous variable?

$\endgroup$
  • $\begingroup$ I am surprised at the data. If you care about buying a car about 55 years old, don't you know exactly what age it is? Aren't they marketed as 1961 Gonzo Dragons, or whatever? (I don't really know about cars.) $\endgroup$ – Nick Cox Apr 7 '16 at 15:11
1
$\begingroup$

In an ANOVA the dependent or response variable is continuous, which is not your case.

You can address the problem as a test of homogeneity between both categorical variables ("age" with 5 levels, and "car" with 3 levels). A chi-square test will quantify the deviation of the observed counts from the expected counts in each cell, based on the marginal counts.

Here is an example with made up data in R:

set.seed(0)    
age = c("<25", "25 - 35", "36 -45", "46 - 55", "> 55")
    car = c("American", "Japanese", "European")
    d = matrix(sample(c(10:30),15), nrow = 3, byrow = T)
    dimnames(d) = list(car=car, age=age)
    addmargins(d)

                          age
car        <25 25 - 35 36 -45 46 - 55 > 55 Sum
  American  28      15     17      20   25 105
  Japanese  13      23     24      18   30 108
  European  10      12     11      29   19  81
  Sum       51      50     52      67   74 294

The expected frequencies are:

round(chisq.test(d)$expected,0)

                      age
car        <25 25 - 35 36 -45 46 - 55 > 55
  American  18      18     19      24   26
  Japanese  19      18     19      25   27
  European  14      14     14      18   20

And the test is,

chisq.test(d)

Pearson's Chi-squared test

data:  d
X-squared = 21.1005, df = 8, p-value = 0.006885

I believe you are dealing with counts, and to assess the data with an ANOVA you would probably have to turn the age data into a continuous variable. However, and in order to preserve the ordinal information contained in the age groups, I did think of applying a Poisson generalized linear model with an ordered explanatory variable (age):

set.seed(0)
age = c("<25", "25-35", "36-45", "46-55", "> 55")
car = c("American", "Japanese", "European")
d = matrix(sample(c(10:30),15), nrow = 3, byrow = T)
dimnames(d) = list(car=car, age=age)
addmargins(d)
require(splitstackshape)
(dat = melt(d))

        car   age value
1  American   <25    28
2  Japanese   <25    13
3  European   <25    10
...
summary(glm(value ~ ordered(age) + car, dat, family = "poisson"))
    Call:
glm(formula = value ~ ordered(age) + car, family = "poisson", 
    data = dat)

Coefficients:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)     3.03115    0.09805  30.915   <2e-16 ***
ordered(age).L  0.32798    0.12939   2.535   0.0113 *  
ordered(age).Q  0.12096    0.13211   0.916   0.3599    
ordered(age).C -0.06739    0.13146  -0.513   0.6082    
ordered(age)^4 -0.06257    0.13545  -0.462   0.6441    
carJapanese     0.02817    0.13705   0.206   0.8371    
carEuropean    -0.25951    0.14788  -1.755   0.0793 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 32.564  on 14  degrees of freedom
Residual deviance: 19.939  on  8  degrees of freedom
AIC: 105.41

Hence, the significant relationship between age and value (presumably the number of purchases) does seem to follow a linear relationship - linearly more cars purchased with increasing age.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ thank you Antoni. I thought there was a way to get around that and still run an ANOVA by allocating values, but maybe not. Cheers $\endgroup$ – Jack Masey Apr 7 '16 at 13:18
  • 1
    $\begingroup$ Note that the chi-square test takes no account whatever of the ordering of age categories. Shuffle the order and the chi-square result will remain the same. $\endgroup$ – Nick Cox Apr 7 '16 at 14:31
  • $\begingroup$ @NickCox I was going to post an edit reflecting that and with an illustration of a generalized linear model. $\endgroup$ – Antoni Parellada Apr 7 '16 at 14:53
  • 1
    $\begingroup$ While I'd have made the same point as Nick, that doesn't mean that one shouldn't consider this analysis -- its suitability depends on the specific question one wants to ask of the data. No actual hypothesis was given, just a very vague "check relationship" ... so there's not necessarily anything wrong with a chi-square. If one is interested in any kind of difference between the age distributions, it would be a good choice. If one is primarily interested in say whether there's a tendency to older ages or younger ages for the different car types, then there are more powerful choices. $\endgroup$ – Glen_b -Reinstate Monica Apr 8 '16 at 1:33
  • $\begingroup$ I will come back to say more on this (and your other post, which is closely related to what I want to discuss) soon. $\endgroup$ – Glen_b -Reinstate Monica Apr 8 '16 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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