问题运行pcor.test(偏相关)
Problem running pcor.test (partial correlation)
这是我的数据集的输入:
structure(list(Year = c("2021", "2021", "2021", "2021", "2021",
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021",
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021",
"2021"), Month_Number = c("8", "8", "8", "9", "9", "9", "9",
"9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9",
"9", "9"), Month_Name = c("August", "August", "August", "September",
"September", "September", "September", "September", "September",
"September", "September", "September", "September", "September",
"September", "September", "September", "September", "September",
"September", "September", "September"), Day_Number = c(29L, 30L,
31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L), Day_Name = c("Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"), Time_Wake = c(730L, 800L, 730L, 500L,
715L, 600L, 600L, 700L, 600L, 700L, 500L, 500L, 500L, 500L, 700L,
645L, 700L, 630L, 645L, 700L, 600L, 700L), Start_Work = c(1400L,
1100L, 930L, 1015L, 1000L, 945L, 1400L, 1500L, 915L, 930L, 1000L,
940L, 840L, 730L, 1700L, 945L, 1040L, 955L, 945L, 930L, 745L,
800L), End_Work = c(1900L, 1755L, 1520L, 1800L, 1600L, 1210L,
1700L, 1515L, 1530L, 1530L, 1800L, 1650L, 1800L, 1410L, 2000L,
1710L, 1430L, 1800L, 1840L, 1720L, 1915L, NA), Mins_Sleep = c(420L,
360L, 360L, 300L, 540L, 540L, 480L, 480L, 480L, 480L, 420L, 300L,
240L, 480L, 300L, 420L, 360L, 390L, 405L, 420L, 360L, 420L),
Workout_Y_N = c("N", "Y", "N", "Y", "Y", "Y", "N", "N", "N",
"N", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N",
""), Time_Workout = c(NA, NA, NA, 730L, 730L, 730L, NA, NA,
NA, NA, 730L, 730L, NA, NA, NA, NA, 735L, 735L, 735L, NA,
NA, NA), Work_Environment = c("Home", "Office", "Office",
"Office", "Office", "Office", "Home", "Home", "Office", "Office",
"Office", "Office", "Office", "Home", "Home", "Office", "Office",
"Office", "Home", "Office", "Home", "Home"), Coffee_Cups = c(4L,
0L, 1L, 3L, 0L, 2L, 6L, 4L, 5L, 3L, 3L, 2L, 2L, 3L, 1L, 1L,
3L, 2L, 2L, 0L, 1L, 1L), Tea_Cups = c(0L, 2L, 2L, 2L, 4L,
2L, 0L, 0L, 2L, 0L, 2L, 4L, 0L, 0L, 0L, 2L, 6L, 5L, 0L, 2L,
0L, 0L), Mins_Work = c(300L, 420L, 310L, 435L, 350L, 145L,
135L, 15L, 60L, 60L, 390L, 395L, 395L, 315L, 80L, 580L, 175L,
545L, 230L, 435L, 370L, NA), Onset_Mood = c("Tired", "Tired",
"Sad", "Angry", "Rested", "Rested", "Rested", "Tired", "Tired",
"Tired", "Rested", "Angry", "Tired", "Rested", "Angry", "Angry",
"Angry", "Sad", "Rested", "Sad", "Tired", "Tired")), class = "data.frame", row.names = c(NA,
-22L))
我只是想 运行 由“Day_Name
”控制的变量“Coffee_Cups
”和“Mins_Work
”之间的偏相关。但是,当我 运行 来自 ppcor 库的偏相关时:
library(ppcor)
pcor.test(x=work$Mins_Work,
y=work$Coffee_Cups,
z=work$Day_Name)
它给我这个错误:
Error in pcor(xyz, method = method) : 'x' 必需是数值 # (Chinese = "Needs to be a numeric value")
我尝试切换 x 和 y 变量,但这似乎也没有影响,尽管它们都是数值。有什么地方我可能做错了吗?
请参阅 pcor.test
的文档,上面写着 Missing values are not allowed
。变量 Mins_Work
缺少值 NA
。
work$Mins_Work
[1] 300 420 310 435 350 145 135 15 60 60 390 395 395 315 80 580 175 545 230 435 370 NA
此外,所有变量都必须是数字,但变量 Day_Name
不是。
work$Day_Name
[1] "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday"
[13] "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"
这是我的数据集的输入:
structure(list(Year = c("2021", "2021", "2021", "2021", "2021",
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021",
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021",
"2021"), Month_Number = c("8", "8", "8", "9", "9", "9", "9",
"9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9",
"9", "9"), Month_Name = c("August", "August", "August", "September",
"September", "September", "September", "September", "September",
"September", "September", "September", "September", "September",
"September", "September", "September", "September", "September",
"September", "September", "September"), Day_Number = c(29L, 30L,
31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L), Day_Name = c("Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"), Time_Wake = c(730L, 800L, 730L, 500L,
715L, 600L, 600L, 700L, 600L, 700L, 500L, 500L, 500L, 500L, 700L,
645L, 700L, 630L, 645L, 700L, 600L, 700L), Start_Work = c(1400L,
1100L, 930L, 1015L, 1000L, 945L, 1400L, 1500L, 915L, 930L, 1000L,
940L, 840L, 730L, 1700L, 945L, 1040L, 955L, 945L, 930L, 745L,
800L), End_Work = c(1900L, 1755L, 1520L, 1800L, 1600L, 1210L,
1700L, 1515L, 1530L, 1530L, 1800L, 1650L, 1800L, 1410L, 2000L,
1710L, 1430L, 1800L, 1840L, 1720L, 1915L, NA), Mins_Sleep = c(420L,
360L, 360L, 300L, 540L, 540L, 480L, 480L, 480L, 480L, 420L, 300L,
240L, 480L, 300L, 420L, 360L, 390L, 405L, 420L, 360L, 420L),
Workout_Y_N = c("N", "Y", "N", "Y", "Y", "Y", "N", "N", "N",
"N", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N",
""), Time_Workout = c(NA, NA, NA, 730L, 730L, 730L, NA, NA,
NA, NA, 730L, 730L, NA, NA, NA, NA, 735L, 735L, 735L, NA,
NA, NA), Work_Environment = c("Home", "Office", "Office",
"Office", "Office", "Office", "Home", "Home", "Office", "Office",
"Office", "Office", "Office", "Home", "Home", "Office", "Office",
"Office", "Home", "Office", "Home", "Home"), Coffee_Cups = c(4L,
0L, 1L, 3L, 0L, 2L, 6L, 4L, 5L, 3L, 3L, 2L, 2L, 3L, 1L, 1L,
3L, 2L, 2L, 0L, 1L, 1L), Tea_Cups = c(0L, 2L, 2L, 2L, 4L,
2L, 0L, 0L, 2L, 0L, 2L, 4L, 0L, 0L, 0L, 2L, 6L, 5L, 0L, 2L,
0L, 0L), Mins_Work = c(300L, 420L, 310L, 435L, 350L, 145L,
135L, 15L, 60L, 60L, 390L, 395L, 395L, 315L, 80L, 580L, 175L,
545L, 230L, 435L, 370L, NA), Onset_Mood = c("Tired", "Tired",
"Sad", "Angry", "Rested", "Rested", "Rested", "Tired", "Tired",
"Tired", "Rested", "Angry", "Tired", "Rested", "Angry", "Angry",
"Angry", "Sad", "Rested", "Sad", "Tired", "Tired")), class = "data.frame", row.names = c(NA,
-22L))
我只是想 运行 由“Day_Name
”控制的变量“Coffee_Cups
”和“Mins_Work
”之间的偏相关。但是,当我 运行 来自 ppcor 库的偏相关时:
library(ppcor)
pcor.test(x=work$Mins_Work,
y=work$Coffee_Cups,
z=work$Day_Name)
它给我这个错误:
Error in pcor(xyz, method = method) : 'x' 必需是数值 # (Chinese = "Needs to be a numeric value")
我尝试切换 x 和 y 变量,但这似乎也没有影响,尽管它们都是数值。有什么地方我可能做错了吗?
请参阅 pcor.test
的文档,上面写着 Missing values are not allowed
。变量 Mins_Work
缺少值 NA
。
work$Mins_Work
[1] 300 420 310 435 350 145 135 15 60 60 390 395 395 315 80 580 175 545 230 435 370 NA
此外,所有变量都必须是数字,但变量 Day_Name
不是。
work$Day_Name
[1] "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday"
[13] "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"