我正在尝试将高斯逆分布拟合到每个参与者的响应时间,以获取每个参与者的分布的mu和lambda。但是,即使我尝试了许多方法,也总是为所有参与者提供相同的输出,而不是分别分配给每个参与者。
我尝试了以下方法:
library(goft)
require(stats)
by(Data, Data[,"Participant"], function (x) ig_fit(Data$RT)))
输出
Data[, "Participant"]: P001G01S01
Inverse Gaussian MLE
mu 448.8195
lambda 6486.4473
Data[, "Participant"]: P002G01S02
Inverse Gaussian MLE
mu 448.8195
lambda 6486.4473
Data[, "Participant"]: P003G02S01
Inverse Gaussian MLE
mu 448.8195
lambda 6486.4473
我期望以下几点:
Participant mu lambda
1 480.252 6005.23
2 521.23 5312.632
3 490.325 6320.53
答案 0 :(得分:2)
这里是tidyverse
的一个选项。按“参与者”分组,在“ RT”上应用ig_fit
,对输出进行转置(t
,在tibble
中将其转换为summarise
Wihtin,包装为list
(因为summarise
期望每组长度为1的元素作为输出,而list
属于length
1),然后unnest
list
返回3列(“参与者”,“ mu”和“ lambda”)的data.framee
library(tidyverse)
library(goft)
df1 %>%
group_by(Participant) %>%
summarise(out = list(ig_fit(RT) %>% t
%>% as_tibble)) %>%
unnest(out)
# A tibble: 2 x 3
# Participant mu lambda
# <int> <dbl> <dbl>
#1 1 460. 10720.
#2 2 472. 5272.
df1 <- structure(list(Participant = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L), RT = c(352L, 526L, 624L, 424L, 356L, 475L, 256L,
426L, 562L, 426L, 526L, 634L), Session = c(1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L), Testing_Condition = c(0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L)), class = "data.frame",
row.names = c(NA,
-12L))
答案 1 :(得分:1)
根据@akrun的建议,较小的更改有效。
library(goft)
require(stats)
by(Data, Data[,"Participant"], function (x) ig_fit(x$RT)))