# Sigmoid fit with user function

Hi rooters!!

Iâ€™m trying to fit the points of TGraph with a user function, in specific a sigmoid function. The data are very simple, consiste in 3 columns, x, y, ye :

1 0.004879 0.000973417
2 0.0154418 0.00172387
3 0.107985 0.00436869
4 0.483777 0.00696569
5 0.694034 0.00646603
6 0.82445 0.00535508
7 0.876391 0.00463985
8 0.911456 0.00395861
9 0.927958 0.00361275
10 0.935383 0.00342981
11 0.923815 0.00375144
12 0.929426 0.00361619

So what I did is:

gr = TGraphErrors( â€śmyfileâ€ť ,"%lg %lg %lg" )
gr.Draw(â€śAPNâ€ť)

func = TF1(â€śfuncâ€ť,"([0]/(1+ TMath::Exp(-[1]*(x-[2]))", 0,12)
func.SetParNames(â€śemaxâ€ť,â€ślambdaâ€ť,â€śHV50â€ť)
func.SetParLimits(1,0.01,5)

gr.Fit(func)

But it doesnâ€™t workâ€¦

Try: ```func = TF1("func", "([0]/(1+ TMath::Exp(-[1]*(x-[2]))))", 0, 12) func.SetParameters(1, 2, 4)```

You need to set the initial parameter values as suggested in the previous post

Ah yes now it works!! Thanks Willie_E_Coyote and moneta!!

Now I have another problem, because Iâ€™m trying to extrapolate the fit parameters, so I did:

sigmoid= TF1(â€śsigmoidâ€ť,â€śgr.GetFunction(func)â€ť,0,10)

Emax=sigmoid.GetParameter(0)
Emax_err=sigmoid.GetParError(0)

Lambda=sigmoid.GetParameter(1)
Lambda_err=sigmoid.GetParError(1)

HV50=sigmoid.GetParameter(2)
HV50_err=sigmoid.GetParError(2)

The error output is:
input_line_84:1:77: error: use of undeclared identifier 'grâ€™
Double_t TFormula____id5604481502741222502(Double_t x,Double_t p){ return gr.GetFunction(((p[0]/(1+TMath::Exp(-p[2](x[â€¦
^
Error in TFormula::Eval: Canâ€™t find TFormula____id5604481502741222502 function prototype with arguments Double_t
,Double_t*
Error in TFormula::ProcessFormula: Could not find gr.GetFunction function with 1 argument(s)
Error in TFormula::ProcessFormula: Formula â€śgr.GetFunction((([Emax]/(1+TMath::Exp(-[Lambda]*(x-[HV50]))))))â€ť is invalid !
Error in TFormula::Eval: Formula is invalid and not ready to execute
gr.GetFunction is unknown.

Anyway I obtain the fit parameters, but not the error parameters which results always zeroâ€¦
And I also tried to extrapolate an value with the command:

wp=sigmoid.Eval(8.2)

But doesnâ€™t worksâ€¦

I solved doing in simply way:

sigmoid= gr.GetFunction(â€śfuncâ€ť)

Thanks a lot to all for your help

I would like also extract a specific X values for a specific Y valuesâ€¦ I know that for to do the inverse you can use:
x=sigmoid.Eval(y)

But I didnâ€™t found the inverseâ€¦ How I can do?

Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.