Lm function with 2 sub groups

Hello, I would like to compare 2 groups with 2 sub goups with LM function.
Can you help me please.

reg1 <-lm((complete_DATA$deltapercBMIDS.PM[complete_DATA$AgeH<10])~(complete_DATA$deltapercTDS.PM[complete_DATA$AgeH>10]))
Error in model.frame.default(formula = (complete_DATA$deltapercBMIDS.PM[complete_DATA$AgeH <  : 
  les longueurs des variables diffèrent (trouvé pour 'complete_DATA$deltapercTDS.PM[complete_DATA$AgeH > 10]')
> complete_DATA$deltapercBMIDS.PM[complete_DATA$AgeH<10]
[1] -53.13 -48.60 -84.60 -57.77  12.30 -14.65   1.77 -57.77
> complete_DATA$deltapercTDS.PM[complete_DATA$AgeH>10]
 [1]  15.40   3.63 -11.13 -45.80 -40.30 -48.27  -4.10 -50.33  -5.77 -30.65  -4.10  10.97  -5.33
[14]  -4.30   5.77  -5.83 -48.27 -35.07 -13.23 -13.87 -51.00 -19.97 -59.13 -31.87  -8.53  15.40
[27] -14.33 -30.93  -2.03  -6.00 -15.50 -35.30 -21.77  10.97  15.40   1.20 -48.27 -35.65  19.83
[40] -10.93   2.90  12.53   2.95 -41.53  -0.97 -23.23  -1.57   7.50 -22.10  19.83 -21.25 -13.87
[53]  -1.70 -32.67 -40.00 -50.33 -50.33  19.03 -50.33 -19.83 -12.63 -51.00  19.83 -48.27  10.97
[66] -50.33 -21.30 -41.53 -40.00   3.17 -58.95 -15.40

lm is used to fit linear models, you can't use a vector to predict values of another vector of different length.

What exactly are you trying to compare? I think there is a fundamental misunderstanding going on here.

Infact I was able to assess the link between the variation of BMI and the age at the beginning of the disease , it does not find a statistical link.
I would like to study the variation of BMI between for children under 10 years and those over 10 years.

thanks

Ok, you could make a linear model between BMI and age because you had values for both in each observation, that is not the case with the subsetting you are doing.

Maybe you want to add an additional feature to your lineal model, identifying each observation as part of one of the two groups,or maybe just comparing the two groups with ANOVA

https://www.google.com/amp/s/www.r-bloggers.com/r-tutorial-series-two-way-anova-with-unequal-sample-sizes/amp/

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.