1
$\begingroup$

I have this dataframe with two categorical variables (Sex and Asian vs. European) and I need to fit a linear model to estimate the weight of a fetus given the day of the echography and these parameters, also I need to test if there is some correlation between Sex and Ethnicity.

  1. I summarize the 2 categorical variables into 1 categorical variable with 4 levels, then I transform it in 3 dummies (ME = male european, FE and FA)

    fit <- lm(weight ~ 0 + days + days:ME + days:FE + days:MA) 
    summary(fit)
    
    Residuals:
          Min        1Q    Median        3Q       Max 
    -0.305911 -0.074343  0.009762  0.081109  0.299959 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
    giorni     0.0113866  0.0001022 111.445  < 2e-16 ***
    giorni:ME  0.0006768  0.0001617   4.187 5.79e-05 ***
    giorni:FE -0.0001183  0.0001575  -0.752    0.454    
    giorni:MA  0.0007811  0.0001657   4.714 7.30e-06 ***
    

    However, I don't know how to test the interaction between Sex and Ethnic group

  2. I don't touch the dataframe and call:

    fit <- lm(weight ~ 0  + days + days:sex +days:ethnic_gruop + giorni:sex:ethnic_gruop)
    
    > summary(fit)
    
    Residuals:
          Min        1Q    Median        3Q       Max 
    -0.305911 -0.074343  0.009762  0.081109  0.299959 
    
    Coefficients: (1 not defined because of singularities)
                            Estimate Std. Error t value Pr(>|t|)    
    days                   1.217e-02  1.305e-04  93.259  < 2e-16 ***
    days:sex0             -7.811e-04  1.657e-04  -4.714  7.3e-06 ***
    days:sex1                    NA         NA      NA       NA    
    days:group1           -1.184e-04  1.575e-04  -0.752    0.454    
    days:sex1:gropu1       1.408e-05  2.398e-04   0.059    0.953    
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    

    And I don't get the estimate of one coefficient...

$\endgroup$
1
$\begingroup$

You don't get the estimate because two variables are perfectly collinear. Your reference (baseline) variable belongs to group 0 and sex0 so estimation of days:sex0 is perfectly collinear with your reference variable. Strangely enough you get NA with days:sex1 coefficient. You should provide a data sample so we can see what went wrong with recoding.

So the age in days influences the weight differently depending on sex and ethnicity (2x2 variables).

People with sex0 and group0 form a baseline category with a corresponding days coeffient.

People with sex1 and group0 form a first contrast with a corresponding days:sex1 coeffient.

People with sex0 and group1 form a second contrast with a corresponding days:group1 coeffient.

People with sex1 and group1 form a third contrast with a corresponding days:sex1:group1 coeffient.

There should obviously be only 4 coefficients but you have 5. Also I don't see any value in recoding variables as you did at point 1. in your question.

$\endgroup$

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.