rdata-analysisdifferencevariable-lengthsignificance

Checking the significance of the difference between two groups of different length


I need to check if the difference between land surface temperature in the past and present within the LULC is statistically significant. LULC units changed over time and the length of the temperature data changed as well because the class grew.

I made data two frames for one of the classes for both periods. LST values from the past have 104 records, from the past - 108.

t.test(compact_midrise_1990$LST1990 ~ compact_midrise_2010$LST2010)

Ends up with:

Error in model.frame.default(formula = compact_midrise_1990$LST1990 ~  : 
  variable lengths differ (found for 'compact_midrise_2010$LST2010')

The question is how can I check the significance of the differences within the two groups of different lengths in this case.

Data looks like this:

DF1

 LCZ1990 LST1990
1       2  14.235
2       2  14.910
3       2  20.534
4       2  15.060
5       2  13.868
6       2  21.732

DF2

LCZ2010    LST2010
1       2  23.045
2       2  24.038
3       2  23.008
4       2  23.680
5       2  23.645
6       2  25.403

Solution

  • You may have meant to use:

    t.test(compact_midrise_1990$LST1990 , compact_midrise_2010$LST2010)
    

    (comma instead of ~).

    In R t.test has two different interfaces. The default interface,

    t.test(A,B) 
    

    tests the hypothesis that the mean of the vector A equals the mean of the vector B.

    the formula interface (with ~) would be used to specify an outcome ~ predictor type relationship between columns.

    So if you had bound your data frame into a single frame:

       YEAR LCZ    LST
    1  1990   2 14.235
    2  1990   2 14.910
    3  1990   2 20.534
    4  1990   2 15.060
    5  1990   2 13.868
    6  1990   2 21.732
    7  2010   2 23.045
    8  2010   2 24.038
    9  2010   2 23.008
    10 2010   2 23.680
    11 2010   2 23.645
    12 2010   2 25.403
    
    

    then you could use:

    t.test(LST ~ YEAR, data=DF)