-1

I am working with a dataset in which I need to compare ordinal data to continuous data in a different column. i.e, individals were categorized (by age, actually) and I need to compare different age ranges to two different test values. I have been attempting to run a multifactor anova, and have had no luck.

First, I subset each age category and tried this:

aov.first.molar<-aov(carbon.combo~first.m.cat.1+first.m.cat.2+first.m.cat.3+first.m.cat.4+first.m.cat.5)
Error in model.frame.default(formula = carbon.combo ~ first.m.cat.1 +  : 
invalid type (list) for variable 'first.m.cat.1'

So the subsets didn't work, so I tried just using the column headers, just to see if it would magically organize by category...

> aov.albania.first<-aov(albania$AgeCat_first~albania$juv_deltaC_dentine+albania$Adult_deltaC_collagen)
Warning messages:
1: In model.response(mf, "numeric") :
 using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors

> summary(aov.albania.first)
Error in levels(x)[x] : only 0's may be mixed with negative subscripts

That obviously didn't work either, and I am not sure what I am doing wrong. I set everything as a factor, and I don't understand why the code is not working. I am wondering if it has something to do with the fact that the nature of my test data is negative. I am not sure how to fix that without altering the data

Here is my data, as requested. I am sorry it's so messy, I am not sure how to format it better. Turning it into a matrix helped, but I am still having problems with anov and ggplot not being able to find certain things that I already turned into factors...

structure(list(Number = structure(1:10, .Label = c("142-c-1", 
"142-c-3", "142-c-5", "156-c-1", "156-c-4", "156-c-6", "157-c-1", 
"157-c-3", "157-c-5", "157-c-6", "158-c-3", "158-c-6", "178-c-1/A", 
"178-c-2/A", "178-c-2/b", "178-c-3/b", "178-c-4/b", "186-c-2/a", 
"186-c-2/b", "186-c-3/b", "186-c-4/b", "186-c-5/b", "186-c-6/b", 
"192-c-1", "192-c-2", "192-c-3", "192-c-4", "192-c-5", "205-c-1", 
"205-c-2", "205-c-3", "205-c-4", "205-c-5", "205-c-6", "210-c-1", 
"210-c-2", "210-c-3", "210-c-4", "210-c-5", "215-c-1", "215-c-2", 
"215-c-3", "215-c-4", "215-c-5", "215-c-6", "215-c-7", "270-c-1", 
"270-c-2", "270-c-3", "270-c-4", "270-c-5", "295-c-1", "295-c-3", 
"295-c-4", "353-c-2", "353-c-3", "353-c-4", "353-c-5", "353-c-6", 
"382-c-1", "390-c-1", "390-c-2", "390-c-3"), class = "factor"), 
ToothID = structure(c(3L, 3L, 3L, 8L, 8L, 8L, 7L, 7L, 7L, 
7L), .Label = c("LI2", "LM1", "LM1-2", "LM3", "LP1-2", "M2", 
"RM1-2", "RM2"), class = "factor"), sex = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("F", "M"), class = "factor"), 
Al.Qahtani.category = structure(c(2L, 5L, 8L, 2L, 5L, 8L, 
2L, 6L, 7L, 8L), .Label = c("AC", "CR 1/2", "CR 3/4", "CRC", 
"R 1/2", "R 1/4", "R 3/4", "RC", "Ri ", "unk"), class = "factor"), 
AgeCat_first = structure(c(1L, 2L, 3L, 2L, 3L, 4L, 1L, 2L, 
2L, 3L), .Label = c("1", "2", "3", "4", "5"), class = "factor"), 
AgeCat_second = c(2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 4L), 
sample_age_first = structure(c(9L, 18L, 23L, 17L, 27L, 6L, 
10L, 13L, 21L, 23L), .Label = c("10.5 to 16.5", "11.5 to 14.5", 
"11.5 to 15.5", "11.5 to 18.5", "11.5 to 19.5", "12.5 to 15.5", 
"12.5 to 19.5", "15.5 to 20.5", "1.5 to 2.5", "1.5 to 3.5", 
"17.5 to 22.5", "2.5 to 4.5", "3.5 to 6.5", "3.5 to 7.5", 
" 4.5 to 6.5 ", "4.5 to 6.5", "4.5 to 7.5", "4.5 to 8.5", 
"6.5 to 11.5", "6.5 to 8.5", "6.5 to 9.5", "7.5 to 10.5", 
"8.5 to 10.5", "8.5 to 11.5", "8.5 to 12.5", "9.5 to 12.5", 
"9.5 to 13.5", "9.5 to 15.5", "unk"), class = "factor"), 
sample_age_second = structure(c(16L, 25L, 7L, 15L, 26L, 7L, 
15L, 22L, 2L, 7L), .Label = c("10.5 to 16.5", "11.5 to 13.5", 
"11.5 to 14.5", "11.5 to 15.5", "11.5 to 18.5", "11.5 to 19.5", 
"12.5 to 15.5", "12.5 to 19.5", "14.5 to 17.5", "15.5 to 20.5", 
"1.5 to 3.5", "17.5 to 22.5", "3.5 to 6.5", "4.5 to 6.5", 
"4.5 to 7.5", "4.5 to7.5", " 5.5 to 6.5 ", "6.5 to 11.5", 
"6.5 to 8.5", "6.5 to 9.5", "7.5 to 11.5", "7.5 to 12.5", 
"8.5 to 12.5", "9.5 to 12.5", "9.5 to12.5", "9.5 to 13.5", 
"9.5 to 15.5", "unk"), class = "factor"), AgeCat_adult = c(9L, 
9L, 9L, 8L, 8L, 8L, 7L, 7L, 7L, 7L), age_at_death = structure(c(3L, 
3L, 3L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("18-30", 
"31-45", ">45", "Adolescent", "Ind"), class = "factor"), 
weight_percent_.N = c(11.5, 6.6, 6.8, 7.8, 8.7, 9.4, 5.6, 
5.6, 9.1, 3.9), weight_percent_C = c(37.8, 26.2, 29.5, 32.7, 
34.7, 34.4, 22, 30.7, 46.8, 22.7), juv_deltaN_dentine = c(4.54, 
4.45, NA, 4.03, 5.73, 6.81, 5.03, 4.58, 0.3, NA), juv_deltaC_dentine = c(-22.042, 
-22.865, -24.345, -23.557, -23.24, -22.282, -22.85, -22.697, 
-25.439, -25.776), juv_proxy = c(7.958, 7.135, 5.655, 6.443, 
6.76, 7.718, 7.15, 7.303, 4.561, 4.224), Adult_deltaC_collagen = c(-18.62, 
-18.62, -18.62, -18.9, -18.9, -18.9, -18.64, -18.64, -18.64, 
-18.64), adult_proxy = c(11.38, 11.38, 11.38, 11.1, 11.1, 
11.1, 11.36, 11.36, 11.36, 11.36), Adult_deltaC_apatite = c(12.29, 
12.29, 12.29, -10.23, -10.23, -10.23, -10.73, -10.73, -10.73, 
-10.73), Adult_deltaN = c(-18.62, -18.62, -18.62, -18.9, 
-18.9, -18.9, -18.64, -18.64, -18.64, -18.64), apatite_collagen_spacing = c(8.66, 
8.66, 8.66, 7.67, 7.67, 7.67, 7.74, 7.74, 7.74, 7.74), Adult_percent_C = structure(c(2L, 
2L, 2L, 6L, 6L, 6L, 7L, 7L, 7L, 7L), .Label = c("14.31%", 
"22.35%", "33.96%", "34.58%", "36.60%", "39.07%", "39.51%", 
"42.12%", "42.17%", "42.29%", "42.81%", "44.01%", "44.72%", 
"45.52%"), class = "factor"), Adult_percent_N = structure(c(14L, 
14L, 14L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), .Label = c("12.16%", 
"12.30%", "13.04%", "13.78%", "14.20%", "14.89%", "14.97%", 
"15.13%", "15.18%", "15.66%", "15.85%", "16.10%", "4.60%", 
"7.98%"), class = "factor"), Adult_CN_ratio = c(3.27, 3.27, 
3.27, 3.31, 3.31, 3.31, 3.25, 3.25, 3.25, 3.25), delta_18O = c(-5.5, 
-5.5, -5.5, -4.79, -4.79, -4.79, -5.39, -5.39, -5.39, -5.39
), CP = c(0.17, 0.17, 0.17, 0.21, 0.21, 0.21, 0.2, 0.2, 0.2, 
0.2), IR_SF = c(3.33, 3.33, 3.33, 3.12, 3.12, 3.12, 3.19, 
3.19, 3.19, 3.19), adult_bone_sampled = structure(c(2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("femur", "humerus", 
"occipital", "temporal", "tibia"), class = "factor")), .Names = c("Number", 
"ToothID", "sex", "Al.Qahtani.category", "AgeCat_first", "AgeCat_second", 
"sample_age_first", "sample_age_second", "AgeCat_adult", "age_at_death", 
"weight_percent_.N", "weight_percent_C", "juv_deltaN_dentine", 
"juv_deltaC_dentine", "juv_proxy", "Adult_deltaC_collagen", "adult_proxy", 
"Adult_deltaC_apatite", "Adult_deltaN", "apatite_collagen_spacing", 
"Adult_percent_C", "Adult_percent_N", "Adult_CN_ratio", "delta_18O", 
"CP", "IR_SF", "adult_bone_sampled"), row.names = c(NA, 10L), class = "data.frame")

CMRoan
  • 9
  • 1
  • 1
    `dput(head(yourdata, 10))` so that we could replicate your problem. You clearly have incorrect data structure. For `aov`, a `data.frame` is most practical. – nya Dec 03 '16 at 20:54
  • It is in a data frame. I didn't post because it is a fairly large table. I think part of the problem is that all my values were negative and anova doesn't like it, I think. I fixed that but now I can't get the anova to plot! It keeps saying that it is one of the factors (x in my anova code) can not be found... – CMRoan Dec 04 '16 at 00:28
  • The code I suggested above will post the first ten lines of your data. Do it and we can fix your problem. – nya Dec 04 '16 at 14:49

1 Answers1

0

Your data corresponds to the second question, and so does this answer.

The way the aov function works is by measuring response as dependent on the categories. The formula thus needs to be designed as variable ~ factor.

aov.albania.first <- aov(juv_deltaC_dentine + Adult_deltaC_collagen ~ AgeCat_first, 
    data = albania)

summary(aov.albania.first)
             Df Sum Sq Mean Sq F value Pr(>F)
AgeCat_first  3  6.480   2.160   1.667  0.272
Residuals     6  7.773   1.296   

The problem with the first question might be similar to this. Further, check str(first.m.cat.1) and reformat the variable to vector.

nya
  • 2,138
  • 15
  • 29