2
$\begingroup$

There are three groups that received different treatments and then learn a task which they are scored on over the course of 60 sessions.

1) How to choose a function to fit? -The best choice in this case would be s=asym/(1+exp((midpt-x)/rate)), but say you didn't know that.

2) How to compare the three groups to see if they are different or not? -For example Group 1 is better/slower than Group 2.

3) Say there is a third factor measured (e.g., weight) how to look for correlation between weight and the curve fit for each individual? -For example use the mean estimates.

enter image description here

R Code to Generate Data:

x<-1:60
n<-5
dat=NULL
par(mfrow=c(4,4))
for(g in 1:3){
for(subj in 1:n){
asym<-rnorm(1,10,3)
midpt<-runif(1,5,40)
rate<-runif(1,0,5)
s=asym/(1+exp((midpt-x)/rate))
s<-rnorm(length(s),s,1)
s[which(s<0)]<-0
dat<-rbind(dat,cbind(g,subj,x,s))
plot(x,s, type="p", pch=16, col=rainbow(3)[g], xlab="Time",ylab="Score",
main=paste("Group",g,":","Subject#",subj)
)
}
}
colnames(dat)<-c("Group","Subject","Time","Score")

The data for the plot:

> dput(dat)
structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 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 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 
58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 
53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 
59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 
55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 
56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 
52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 
58, 59, 60, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 
53, 54, 55, 56, 57, 58, 59, 60, 0, 1.03158619583643, 0.0700928693799847, 
0, 0, 0.533480242356568, 0, 0, 0.313246505626844, 0, 0.201551652833782, 
0, 0, 8.58420236367213, 7.2151582207413, 6.76349698933596, 8.43232503189182, 
7.84113269530773, 7.48036740442613, 7.22860126336753, 6.23889089933047, 
7.5993822730141, 8.97711255338355, 8.51408365480236, 7.33679466179734, 
8.07177922774387, 7.46193250657315, 6.69880073822405, 8.7239879783316, 
8.63777777133611, 7.32811771015052, 8.21150317871178, 6.75210022817865, 
9.19584687427251, 8.84904099669932, 8.12546344066828, 7.42498538242589, 
7.43402031096714, 7.95799796160173, 6.75415984451499, 8.41849594339, 
6.45648891349807, 8.36526948269262, 6.73507595185595, 9.59230196004733, 
6.8481757733426, 7.5336436175937, 7.26145341491774, 6.84374696765792, 
5.77076068283607, 9.84247282482329, 7.78925766764691, 6.50711775948628, 
8.19902246920613, 8.01867704068551, 7.71330298589825, 8.50368409962827, 
8.36500008512313, 8.37090214729723, 7.28633938219456, 0, 1.65008045947966, 
0.575606733495696, 0, 0.786060958385394, 0, 1.54869682228415, 
0.168946971854925, 0, 0, 0, 0, 0, 0.213101769560987, 0.440700799230945, 
0, 0, 0.190648393014687, 0, 0.774590152871335, 0, 0, 0, 0, 0.178064415218869, 
0, 0, 0.376138177422834, 0.458985077565505, 0.917398964689014, 
1.78416461506729, 1.37112772722134, 2.63275499887878, 0.247691262888474, 
2.71308742063024, 3.41901470336746, 4.11919704486841, 4.04233691698445, 
4.97741716048949, 4.5916456213906, 3.74309103176392, 6.25015151641352, 
5.01570149643103, 5.02144478232446, 6.44037624126331, 4.36299946803298, 
4.81397614036387, 4.21616606222475, 3.94904834726585, 6.2725119824346, 
4.96221630092668, 4.85059793371767, 6.98468854857044, 6.13751640244375, 
5.31975082309877, 4.95974732120037, 4.96944203644392, 5.04695972379456, 
5.55090724593748, 4.9072728753408, 0, 0, 1.27148334131862, 0, 
0, 0, 0, 0.549249296594036, 0, 0, 0, 0, 0.797894117158937, 0.76474221921926, 
0.384456323004612, 0.753724350710486, 0.210172266893594, 0.778029999658896, 
0, 1.20840679374069, 2.27515993940812, 2.33021789487285, 2.48682959545432, 
2.77439234964342, 2.57654149782979, 3.6899693083328, 2.84497438582907, 
4.53576090191172, 5.31904443998464, 5.83484731859952, 4.16995891072675, 
7.46357804432578, 8.0189267920945, 10.1186546998081, 9.17802346129456, 
9.91280676028886, 8.6358637300104, 10.6171626191218, 10.60862571782, 
8.90168548865334, 11.6613913866556, 11.494344312576, 9.83605794475883, 
10.5086341235427, 8.57098156695857, 10.6578914329804, 11.3242140265126, 
10.6128797597814, 8.93858406115906, 11.442477317725, 10.2773057203746, 
11.422141318439, 10.4578041679639, 11.2805966086809, 10.9729630215866, 
10.6400309657672, 10.5325561935863, 10.3806803061043, 12.2462712098331, 
11.1739112019198, 0, 1.37519992104938, 0.00230181625672307, 0.498711700484401, 
0.271234286784188, 0, 0.546777568628416, 1.02624761127694, 0, 
0.802875563963303, 0, 0.75661766368099, 0.859889392170508, 0.771882758754063, 
2.68818858778084, 0, 1.69857213256685, 0, 0, 0, 0.509209770872453, 
0, 0.75119289550595, 0, 0.792697602543835, 0.99601355947128, 
0.615579450984568, 2.25557535234532, 1.14413794471848, 0.111971817227507, 
1.29934159296573, 0.109732809889403, 1.44834021140093, 4.61542498626519, 
5.20534003980441, 7.58289763660421, 7.05378158533781, 6.48087001005784, 
7.46752691991914, 7.06731997153742, 8.43297260855126, 7.26972090539512, 
7.38136834636119, 7.40544432675767, 7.75642154862361, 6.76324320314802, 
5.59456019542772, 7.40022245947996, 7.48835520637033, 7.65877703591718, 
8.21148150997923, 6.6599237915552, 8.0160411529529, 6.60139606432752, 
8.65128003881004, 5.79775256308877, 6.85878904841619, 7.84674726214019, 
4.3467120746636, 7.55232892761264, 0, 0.499583639143117, 0, 0, 
0.31485702801172, 0.3515816928799, 0.931603213795884, 0.206120594561129, 
0, 0, 0.360932275745327, 0.433044022640932, 0, 2.39516067822733, 
2.72351140421486, 0.484924178938609, 0, 0.224022539659828, 0.911042602837107, 
1.31501526265012, 1.94337905383981, 0.595289303995586, 2.41167836489199, 
4.88047662904194, 3.60477176392402, 4.70295731707599, 5.46521105212445, 
5.91105387042816, 7.92754559701199, 6.30579526052163, 7.94051926136399, 
8.93734485763105, 8.10797265204026, 7.47519696905344, 7.87790798680286, 
8.37458434707145, 9.88966658479798, 9.3828993940551, 10.7502415658999, 
8.59224045217057, 8.97257663583808, 9.81078210053123, 8.50519146337723, 
9.80410794437355, 9.90656980648206, 8.95149994048142, 8.08214817120231, 
9.15819742292325, 9.35229009595692, 8.66137979115357, 7.61365572420257, 
10.1643174026938, 10.0183955498814, 7.4284240739572, 8.70163824293303, 
8.97812942423644, 8.40596894398334, 8.9355272887446, 10.7662692661888, 
10.0322226889031, 0, 1.17127841967856, 0, 0, 1.33105575939346, 
1.26518317997976, 0.909776451243087, 0, 1.17988956763035, 0, 
0.762002789890116, 0, 0.832083512904214, 0.45869046938725, 0.64237344364855, 
0, 0, 1.70209058186332, 0.0156597425215317, 0.530568921018249, 
1.50289220053205, 1.20254177632711, 1.90295146480201, 2.81271374240921, 
3.68747746746046, 4.52706950129025, 3.93442281955956, 2.5515226646154, 
5.01710413340776, 6.26260874497632, 5.49950756302542, 6.14255023572, 
7.64342305367938, 9.89655193964118, 8.77398103235339, 7.64631421131576, 
7.77582538877235, 8.30983971196275, 7.8411138994189, 8.23146449905929, 
8.78847752071418, 7.98107466126393, 10.070698869224, 11.4707954191209, 
10.7802260341204, 9.57883214145681, 9.45484978547647, 9.48982907075886, 
9.1970407665382, 11.6749555300959, 9.63111689744601, 8.58499382409839, 
11.1715368888387, 9.05676905125274, 9.62946264711658, 9.58942799488546, 
9.85519469529828, 11.3423886432642, 10.2388217496706, 9.321088820638, 
2.54991829591086, 1.46892808704928, 1.33731418668811, 2.61646582984654, 
2.66441558379904, 1.94155905469566, 2.04033379550069, 2.48570760395896, 
4.42042378981082, 7.39539169831503, 7.13750763644472, 7.56179540351745, 
8.3182611498041, 9.08500888550381, 9.70808482796405, 7.73515608944475, 
8.84736021599179, 9.91632970815538, 6.85549285375218, 9.28524174344136, 
9.90944985145035, 9.80872079378178, 7.50153753628047, 9.43229031930222, 
8.38966493676363, 9.09120122077017, 8.03664950919612, 9.3394983271658, 
8.75907130568531, 9.48293724329285, 12.4992084970297, 8.65195448377916, 
8.12867324807331, 9.35139039060214, 7.45991827498198, 7.99054707729177, 
9.33353246911462, 10.0140575953154, 9.62351889572776, 8.24274614700205, 
8.58318657774853, 10.7558360231622, 8.02327882376913, 9.71166452940178, 
10.0019440376244, 9.45855647023341, 9.69119327483915, 10.7993477282601, 
10.0843411976038, 9.11504744632914, 6.8274470318345, 8.99834673719741, 
7.79205423949022, 9.36012575556776, 7.89124643127951, 9.30281848417072, 
8.74860790084056, 9.5283366549812, 9.38344434187134, 10.2903751565271, 
0.453745586179272, 0, 0, 0, 0.873987314878141, 0, 0.722662147827297, 
0.403389511042975, 0.306843142235151, 1.02980154677912, 1.26162245184229, 
0, 0.738903729490879, 1.09034307241339, 0, 1.58160726939009, 
1.00967640268439, 0, 0.80185808962151, 2.32319612854146, 0.680322447550744, 
3.45272401214232, 3.98795894572399, 3.07813212524925, 2.74649863082109, 
6.22716830523846, 6.0055534600751, 8.61611296275224, 7.43196060556798, 
10.8845246381959, 9.35652157761648, 13.535727140111, 11.8228054818836, 
13.6576101040097, 14.5985384582905, 14.720679614782, 16.4464360616433, 
15.650288548452, 17.1098996963077, 15.9900299666647, 15.1733513084352, 
13.460940246974, 17.1560722762101, 16.3594343339547, 17.6334893606005, 
15.4742543462313, 17.9252909798281, 16.0685717969627, 16.5922216823379, 
17.4019406800853, 16.4827827623591, 16.2283964030323, 17.3342536279416, 
18.0418680171866, 16.7384801226295, 16.6891351719263, 16.9196389730558, 
17.4360442891675, 17.9082826953212, 17.9080493357515, 0, 2.12708907689137, 
0.180057921261079, 1.10881706586506, 0, 0.0121433242856085, 0.297984364375141, 
0, 0, 0, 2.44423336550259, 0.203063335897161, 0, 0, 1.6324104596689, 
2.62199381849, 4.65386129828348, 8.1727461408628, 8.46401772635808, 
9.53664285078371, 10.6167429148595, 14.1642559994959, 14.1737553430174, 
11.7871799896131, 11.6842610420266, 13.3115074910252, 12.542611801357, 
11.7928591701523, 13.3234935331678, 13.3703045475931, 11.1816912869155, 
12.7919758124473, 14.1524237174757, 13.7740194661304, 13.4163111242968, 
12.1519239667949, 12.3411763952143, 14.1146449302467, 10.9799552937331, 
11.9519542581919, 13.5564141397704, 12.6603319807821, 13.4818352225032, 
12.4199788441116, 12.8984348945313, 12.4901614053039, 12.6826270147467, 
12.8972689922525, 12.8761297786996, 14.5082862520908, 13.3088273305523, 
11.689683656794, 11.6905619013621, 12.9372150020277, 11.5355247094442, 
13.2387324569227, 13.2672299010805, 13.8721895345878, 13.6468900741745, 
10.2407254663892, 0, 0, 0, 0.647542861902527, 0, 0, 0.150952145577755, 
0.957392963769722, 0.0609913610066249, 0.120528953161183, 0, 
0, 0, 0.704879442804958, 1.78408096310525, 0, 1.65023390832557, 
0, 0.0923652900702186, 0, 0, 0, 0.0450577278912485, 0.751091209975893, 
1.43744886707744, 0, 0, 0.402523264684891, 0, 2.18009214813759, 
0.771506994461835, 0.366208114547776, 2.94463744259694, 3.23887911393408, 
1.32442373753528, 2.39016677599377, 2.11611119824864, 4.4636528481399, 
6.31011316007659, 5.93705422891922, 6.86234582501057, 7.04191497749316, 
8.65532314557916, 7.94975578786001, 8.32465895135107, 10.2544694107277, 
10.612243226875, 11.0923080512734, 11.330145953257, 10.9264546212034, 
11.2641173880016, 13.725651001296, 12.4933952691916, 11.6957249070898, 
9.83082658829007, 10.1737819351518, 10.0278938736921, 10.2885620365588, 
11.4721405494207, 10.4049091351876, 0, 0.749971887045118, 0.0935661865127177, 
0, 0.276694847632314, 2.16959186220499, 1.03997487041489, 1.3157745452179, 
2.55444161550264, 5.55564346433049, 6.5606015783716, 6.26361090505197, 
8.21561991560817, 8.18272868467541, 10.3969243810899, 11.2467666988384, 
11.9401702885542, 11.4225328143267, 12.0539674679589, 12.0500044044004, 
11.9905170877494, 10.2276294132972, 13.8701081425486, 12.2345025406528, 
12.1581776929614, 12.2557621066668, 14.8327853422983, 13.5706592392689, 
11.670858423701, 12.1264565841421, 10.9882135554883, 11.910278334423, 
12.2622517792821, 11.1803535948265, 12.3218944257386, 12.4022799379156, 
13.3489881438595, 12.1519181213977, 11.8546766797642, 12.803931564254, 
12.0702080416288, 11.7787770410977, 12.891356400286, 13.5826348158223, 
13.7637998730129, 12.4586804497261, 13.5973025845184, 11.7437527504006, 
11.9123359201718, 12.5433135233633, 11.6795905695007, 12.8596795881007, 
12.2905970480821, 12.6113804745829, 11.2696221922899, 11.6150967135138, 
12.5065320547622, 11.0547024118768, 12.4539473082803, 12.7320989917665, 
0.828387327199212, 0, 0.678802434035732, 0.862374178714765, 1.2684255030382, 
0, 1.83576620899006, 4.71180773591447, 7.15854703611923, 9.98309590659522, 
12.238244011289, 10.1107587439567, 11.9735917806089, 10.4329498397988, 
11.5227705911928, 11.0857295162145, 12.2887936081285, 11.5414959841271, 
13.0408942545176, 12.1105317096253, 12.278626227706, 12.928520689136, 
12.7511178109053, 12.8603069946746, 12.0171195930741, 10.8521389192071, 
11.1200911135579, 12.6196298934609, 13.0379900612457, 11.9235143903274, 
10.5663812910848, 9.58631186189439, 12.3408962856898, 11.8850627357227, 
11.4640087047838, 11.6422475778865, 11.7972751414621, 12.4895822567521, 
12.5922359409969, 11.3441135167686, 11.1062090592898, 13.5286995172176, 
10.9736620416305, 9.97146752611849, 12.1805784426637, 10.4799209638073, 
12.000342774528, 10.0789727398843, 11.8248401081463, 10.9804844946854, 
11.835301869748, 12.6690753183117, 13.0419456703609, 10.5160699826278, 
11.0290656985927, 11.2908514684923, 13.2547962666313, 11.716640532936, 
10.8753781493541, 12.8659989966435, 0.233214052916719, 0, 0, 
0, 0.666797775504629, 1.03113449232196, 0, 0, 0.235911824664366, 
0.643988682300099, 2.35216791250754, 4.48251004203957, 6.27829837596023, 
7.80685682111985, 8.85867907137818, 11.0234994200981, 10.659303622617, 
8.83821767964211, 10.6285040270975, 11.9610855075861, 9.98850567573665, 
9.38183764798606, 9.12964903103025, 9.79518026168435, 10.2486037764971, 
10.7399919605559, 10.4000561384545, 10.1195650266721, 10.8172633161224, 
11.7290460025207, 9.55500863048794, 9.51997696957129, 8.136245145294, 
10.0898702564584, 8.83124284475855, 9.53702720995183, 10.234965256881, 
11.8832880596309, 11.0260846401941, 10.3616281489605, 11.1595975463324, 
10.6065362312525, 11.7789145668303, 10.7391985633112, 8.7345559786342, 
9.83721824425054, 9.87969316669263, 11.0054313800222, 9.45630790909011, 
10.8026069853639, 10.7823164169656, 8.78222450286674, 9.88401914578533, 
9.49819408578393, 11.1070575565997, 9.80251606293417, 11.6800557898553, 
10.6628812540799, 10.3481870385697, 8.99926635802634, 2.0658714541966, 
0, 0, 0, 0.643696068708256, 1.95882560158578, 1.46771793144107, 
0, 0, 0, 0, 1.57807910644584, 0, 3.15566724378049, 4.15202850585111, 
4.49986707099665, 6.29955267584495, 8.11631515638246, 8.6413891325569, 
8.63053991475974, 8.02359584421251, 9.22297649026951, 8.5220554417732, 
7.83394559530608, 8.05150333895255, 8.81497999527858, 8.32251493454089, 
8.68646050203423, 8.30964562140176, 6.24790293399363, 7.50865404587946, 
7.92394725060917, 7.85279621262117, 9.79363556954982, 8.33078748739039, 
11.0010688083092, 7.87335403086467, 8.04400683453104, 8.87349257925123, 
5.34416893325697, 7.16402027526085, 9.18892534710063, 7.37307377041812, 
9.12042575487411, 7.13803128469491, 9.53932820803311, 7.2471488352217, 
8.13462753251326, 9.32994365735403, 8.9143655639326, 8.68129951409304, 
8.06584003431567, 7.00267444564897, 10.8518954588216, 8.09952530895893, 
9.52528768838161, 8.0767001453374, 7.54472269908506, 8.2017301034284, 
8.93945165288032, 0.664837492834661, 1.42967883870151, 1.21461210510671, 
1.52247428784209, 1.5857475270794, 4.21788588756755, 4.07472703605436, 
4.52783139621065, 4.61304565650941, 4.97223959138618, 7.17290663409386, 
7.55151237688616, 7.23137033191666, 5.6507989759957, 9.61894330860323, 
8.44955835598088, 7.7741137106094, 7.07096361575731, 9.79144128185851, 
10.5769775728822, 9.65529577781692, 9.13039573776741, 9.25919197691465, 
9.45335765533184, 8.9662422782295, 9.18219296678602, 9.47685142345247, 
10.0756859334663, 10.0817513792461, 11.0084378809858, 9.78118846695106, 
9.76090117884639, 8.92844816510047, 8.16642032644479, 10.0468897494144, 
9.04894852060757, 10.9828155120775, 9.93150745149563, 9.30769292314918, 
11.0035921724632, 12.2009103535073, 11.6412800632603, 11.2191465078207, 
10.2601299220248, 10.3150450691667, 9.14815709751079, 10.1162531475645, 
8.50753892237624, 9.53758392124005, 10.8216774355975, 9.5098305251634, 
10.4837560161139, 10.2617540070955, 10.038654859975, 9.00812936944552, 
10.7869945837923, 9.91834237561623, 11.0188750966019, 11.2219462128563, 
10.9428246709094), .Dim = c(900L, 4L), .Dimnames = list(NULL, 
    c("Group", "Subject", "Time", "Score")))
$\endgroup$
3
+100
$\begingroup$

1. Your data clearly suggests sigmoidal function. However, you can try to fit any curve including a polynomial function (of arbitrary order).

JAGS code for fitting a cubic spline:

model {
  for (g in 1:G) {
    for (s in 1:S) {
      for (i in 1:N) {
        mu[g, s, i] <- beta[g, s, 1] +
                       beta[g, s, 2]*x[i] +
                       beta[g, s, 3]*pow(x[i], 2) +
                       beta[g, s, 4]*pow(x[i], 3)
        y[i, g, s] ~ dnorm(mu[g, s, i], tau) T(0, )
      }
    }
  }

  tau ~ dgamma(0.01, 10)

  for (g in 1:G) {
    for (s in 1:S) {
      for (k in 1:4) {
        beta.mu[g, s, k] ~ dnorm(0, 100)
        beta.tau[g, s, k] ~ dgamma(0.01, 10)
        beta[g, s, k] ~ dnorm(beta.mu[g, s, k], beta.tau[g, s, k])
      }
    }
  }
}

Save the code to "model1.jag", then fit & examine with rjags:

library(rjags)
data <- list(G = 3, S = 5, N = 60, x = x,
             y = array(dat[,4], c(60, 3, 5))
model <- jags.model("model1.jag", data = data)
update(model, n.iter = 1000)
output <- coda.samples(model = model,
                       variable.names = c("beta"),
                       n.iter = 10000, thin = 10)
print(summary(output))
plot(output)

Note that this model takes into account data truncation (score >= 0).

2. This could be addressed with Bayesian oneway ANOVA. The idea is to fit a linear model for a single nominal predictor — a vector $\langle 1, 0, 0\rangle$ for Group 1, $\langle 0, 1, 0\rangle$ for Group 2, etc.

A simplistic JAGS model:

model {
  for (g in 1:G) {
    mu[g] <- a0 + a[g]
    for (s in 1:S) {
      for (i in 1:N) {
        y[i, g, s] ~ dnorm(mu[g], tau) T(0, )
      }
    }
  }

  # Priors
  tau <- pow(sd, -2)
  sd ~ dunif(0, 10)

  a0 ~ dnorm(0, 0.001)
  for (g in 1:G) {
       a[g] ~ dnorm(0.0, a.tau)
  }
  a.tau <- pow(a.sd, -2)
  a.sd ~ dunif(0, 10)
}

Fit with R script:

library(rjags)
data <- list(G = 3, S = 5, N = 60,
             y = array(dat[,4], c(60, 3, 5)))
model <- jags.model("model2.jag", data = data)
update(model, n.iter = 1000)
output <- coda.samples(model = model,
                       variable.names = c("a0", "a"),
                       n.iter = 10000, thin = 10)
print(summary(output))
plot(output)

Then examine normalized group deflection b: b[j] = a[j] - mean(a), b0 = a0 + mean(a)

The best source on this subject is chapter 18 of Kruschke, John. Doing Bayesian Data Analysis: A Tutorial with R and BUGS.

$\endgroup$
  • $\begingroup$ Am I correct that your second model is not taking into account that the scores are changing over time? It is just comparing the overall group means? $\endgroup$ – Flask Dec 27 '13 at 20:29
  • $\begingroup$ That's correct. However, you can fix model to include time as another predictor: mu[g, i] <- a0 + a1[g] + a2[i] + a12[g, i] ... y[i, g, s] ~ dnorm(mu[g, i], tau) T(0, ) Then get deflections by averaging over parameters: b0 <- mean(mu[,]) b1[g] <- mean(mu[g, ]) - b0 b2[i] <- mean(mu[, i]) - b0 $\endgroup$ – Oleg Smirnov Dec 28 '13 at 14:58
  • $\begingroup$ Thanks, I need to investigate this further but I believe it answers my question. It is different from what I came up with. One further question is on your choice of prior on the sd. What if instead a gamma prior was used on the precision and the results were different? How would you choose between the two? $\endgroup$ – Flask Dec 28 '13 at 15:42
  • $\begingroup$ See for example, Andrew Gelman's discussion of the issue here: Prior distributions for variance parameters in hierarchical models. It is not clear to me how this applies to your approach. $\endgroup$ – Flask Dec 28 '13 at 15:49
  • $\begingroup$ Thanks for the paper. If I understood it correctly, a gamma prior might be a poor choice because of its density near zero which will cause unwanted distortion. A better prior for a.tau would be a.tau <- pow(a.sd, -2) a.sd <- abs(a.sd.t) a.sd.t ~ dt(0, 0.001, 2) However, a uniform for y's sd will work just fine provided that you have enough data to overwhelm this not very informative prior. $\endgroup$ – Oleg Smirnov Dec 29 '13 at 19:30
2
$\begingroup$

I would approach this as follows:

(1) Just looking at the data, I would immediately try to fit a sigmoid curve to each function. If you wanted, you could use AIC (see link) justify this choice -- you could try fitting a bunch of other candidate models, but none would produce a better fit.

See: http://en.wikipedia.org/wiki/Akaike_information_criterion

(2) When you fit the sigmoid you can calculate a mean and standard error (or a confidence interval if you like) for each parameter that is fit (midpt & rate in your terminology). I've put a link below that shows how you can do this in MATLAB (not R, unfortunately). You could also use bootstrapping to generate CIs or test statistics.

Once this is done, you can test whether any two fits are significantly different in a certain parameter. It is essentially the same as seeing if two linear fits to different data have significantly different slopes (see second link). Use ANOVA if you want to compare more than just two fits.

See: http://www.mathworks.com/matlabcentral/fileexchange/42641-sigmoid-logistic-curve-fit

See: http://r-eco-evo.blogspot.com/2011/08/comparing-two-regression-slopes-by.html

(3) If you've followed #2 above, then you have distilled each of your subjects responses into two variables (midpt & rate). Thus, you can correlate either of these variables with the weight of the subject. You could even plot error bars given the standard error above.

$\endgroup$
  • $\begingroup$ This situation differs somewhat from the regression slope example because each parameter fit is an estimate itself. $\endgroup$ – Flask Dec 27 '13 at 20:42
  • $\begingroup$ @Flask - I don't quite understand what you mean. Are you saying that the regression model (i.e. a sigmoid) is an estimate itself? My point is that you should pick a model up front that makes sense. I would use AIC to justify using a sigmoid. Then, having established your model, you can perform statistical tests to compare their estimated parameters, which is directly analogous to comparing the estimated slopes of two different pairwise linear regressions. This approach seems simpler, but perhaps less flexible(?) than Oleg's answer. Let me know if I'm misunderstanding something. $\endgroup$ – Alex Williams Dec 27 '13 at 23:56
  • $\begingroup$ I mean that in calculating the group average midpoint I will need to take the average of the individual midpoints which are not data but parameters estimated from data with uncertainty attached. The issue is similar to this question $\endgroup$ – Flask Dec 28 '13 at 0:56
  • $\begingroup$ Yes you are correct if you want to pool the data like that. Sorry I misunderstood your question. $\endgroup$ – Alex Williams Dec 28 '13 at 1:05
  • $\begingroup$ Your approach is similar to mine but I am still not sure how to deal with the additional uncertainty of the parameter estimates for this case. In the case of the linked question it was ok to simply take the averages, but that was measurement error not estimation error. A hierarchial model will allow estimating the group mean exactly but as the model gets more complicated the outcome appears to depend more and more on the exact specification/assumptions which is disconcerting. $\endgroup$ – Flask Dec 28 '13 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.