Sigmoid fit with user function

Hi rooters!! :slight_smile:

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…
thanks a lot in advance for your help!! :slight_smile:

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!! :slight_smile:

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…

Thanks a lot in advance for your help!! :slight_smile:

I solved doing in simply way:

sigmoid= gr.GetFunction(“func”)

Thanks a lot to all for your help :wink:

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 :slight_smile:

TF1::GetX

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