2016-12-03 105 views
-1

我正在處理一個數據集,在這個數據集中我需要將序數據與不同列中的連續數據進行比較。即個體被分類(實際上按年齡),我需要將不同的年齡範圍與兩個不同的測試值進行比較。我一直試圖運行一個多因素anova,並沒有運氣。多因子anova不斷給出錯誤代碼

首先,我集中每一個年齡段,並試圖此:

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' 

所以子集沒有工作,所以我只是用列標題,只是爲了看它是否會神奇地按類別組織嘗試。 ..

> 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 

這顯然也沒有工作,我不知道我在做什麼錯了。我將一切都設置爲一個因素,我不明白爲什麼代碼無法正常工作。 我想知道是否與我的測試數據的性質是負面的事實有關。我不知道如何解決這個問題,而不改變數據

這是我的數據,根據要求。對不起,它太亂了,我不知道如何更好地格式化它。把它變成一個矩陣幫助,但我仍然有ANOV問題和ggplot不能夠發現我已經變成因素某些事情......

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") 

+1

'dput(head(yourdata,10))''這樣我們就可以複製你的問題。你顯然有不正確的數據結構。對於'aov','data.frame'是最實用的。 – nya

+0

它在一個數據框中。我沒有發佈,因爲它是一個相當大的表。我認爲問題的一部分是我的所有價值都是負面的,而安諾娃不喜歡它。我解決了這個問題,但現在我無法得到anova的陰謀!它一直說這是我找不到的因素之一(x在我的anova代碼中)... – CMRoan

+0

我上面建議的代碼將發佈數據的前十行。做到這一點,我們可以解決您的問題。 – nya

回答

0

你的數據對應於第二個問題,這個答案也是如此。

aov函數的工作方式是通過測量依賴於類別的響應。該公式因此需要設計爲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 

第一個問題的問題可能與此類似。此外,請檢查str(first.m.cat.1)並將變量重新格式化爲vector