我有一套数据集,有三种分类变量:状况、次和次;延迟。 这里是我的数据的简化版本(实时数据更长)。
sub condition delay later_value choiceRT later_choice primeRT cue 10 SIZE 10 27 1832 1 888 CHILD 10 PAST 5 11 298 0 1635 PANTS 10 SIZE 21 13 456 0 949 CANDY 11 SIZE 120 22 526 1 7963 BOY 11 FUTURE 120 27 561 1 4389 CHILDREN 11 PAST 5 13 561 1 2586 SPRING
I have a complicated set of procedures to apply to these data (details are not important) I wrote the following function that accomplishes what I want when split by the three grouping variables. It returns 3 variables that I am interested in (indiff, p_intercept, & p_lv)
getIndiffs <- function(currdelay){
if (mean(currdelay$later_choice) == 1) {
indiff = 10.5
p_intercept = "laters"
p_lv = "laters"
}
else if (mean(currdelay$later_choice) == 0) {
indiff = 30.5
# no p-val here, code that this was not calculated
p_intercept = "nows"
p_lv = "nows"
}
else {
F <- factor(currdelay$later_choice)
fit <- glm(F~later_value,data=currdelay,family=binomial())
indiff <- -coef(fit)[1]/coef(fit)[2]
if (indiff < 10) indiff = 10.5
else if (indiff > 30) indiff = 30.5
p_intercept = round(summary(fit)$coef[, "Pr(>|z|)"][1],3)
p_lv = round(summary(fit)$coef[, "Pr(>|z|)"][2], 3)
c(indiff,p_intercept,p_lv)
}
我正试图 d忙地将数据应用于三个组别变量的每一次数据:
ddply (data,.(sub,condition,delay),getIndiffs)
然而,当我执政时,我发现错误。
Error in list_to_dataframe(res, attr(.data, "split_labels")) : Results do not have equal lengths
奇怪的是,当我只使用1组变数,但用2+ error倒错误时,这种工程就会被罚款。
Also, when I "simulate" splitting the dataset myself into a data drame only containing a subset split by the 3 grouping variables, my function works just fine. (Note: I ve tried different ways of returning 3 variables or even returning just 1 variable and it does not work, either)
基本上,我想知道的是,如何利用电压器来利用功能来回多个变量。
对我的问题的任何其它解决办法也受到欢迎。