have data from a movement control experiment in which participants were timed while they performed a task, and given a score (failure or success) based on their performance. As you might expect, we assume participants will make less errors as they have more time to perform the task.
Visualizing the data gives me:
I can fit my desired model to this using cftoolbox, but a least squares fit doesn't make sense for binary data. Just to illustrate:
My attempts to fit the model using fmincon are below. This returns the error "Error using fmincon (line 609) Supplied objective function must return a scalar value."
Could anybody help me change my code to get a fit to the following sample data?
time = [12.16 11.81 12.32 11.87 12.37 12.51 12.63 12.09 11.25
7.73 8.18 9.49 10.29 8.88 9.46 10.12 9.76 9.99 10.08
7.48 7.88 7.81 6.7 7.68 8.05 8.23 7.84 8.52 7.7
6.26 6.12 6.19 6.49 6.25 6.51 6 6.79 5.89 5.93 3.97 4.91 4.78 4.43
3.82 4.72 4.72 4.31 4.81 4.32 3.62 3.71 4.29 3.46 3.9 3.73 4.15
3.92 3.8 3.4 3.7 2.91 2.84 2.7 2.83 2.46 3.19 3.44 2.67 3.49 2.71
3.17 2.97 2.76 2.71 2.88 2.52 2.86 2.83 2.64 2.02 2.37 2.38
2.53 3.03 2.61 2.59 2.59 2.44 2.73 ]
error = [0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1
0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1
0 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1
1 1 0 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];
%Code:
% initial parameters - a corresponds to params(1), b corresponds to params(2)
a = 3.0;
b = -0.01;
LL = @(params) 1/1+params(1)*(log(time).^params(2));
LL([a b]);
pOpt = fmincon(LL,[a b],[],[]);

 채택된 답변

Torsten
Torsten 2018년 10월 25일
편집: Torsten 2018년 10월 25일

0 개 추천

I don't understand your LL-function:
1/1+params(1) ?
Shouldn't the "error" array enter LL somewhere ?
Further, you will have to take the sum of squares of your expression such that LL returns one single value, not a vector.

댓글 수: 4

Rob Hardwick
Rob Hardwick 2018년 10월 25일
To clarify, the desired function is:
error = 1/1+a*(log(time)^b)
I thought the correct way to formulate this was:
LL = @(params) 1/1+params(1)*(log(time).^params(2))
LL=@(params)sum((1./(1+params(1)*log(time).^params(2))-error).^2)
Rob Hardwick
Rob Hardwick 2018년 10월 25일
Thanks so much, this seems to be the solution! If you wouldn't mind, might you be able to help me understand where I was going wrong here?
You have measurements (time(i),error(i)) and you want to fit these data to a function
error_sim = 1/(1+a*log(time)^b)
To this end, you have to minimize the sum "s" of squared differences between measured and simulated data:
s = sum_{i=1}^{i=n} (error_sim(i)-error(i))^2
and that's the objective function to be minimized for fmincon.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

질문:

2018년 10월 25일

댓글:

2018년 10월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by