Skip to main content
Became Hot Network Question
added 21 characters in body
Source Link

I have the following dataset: enter link description heredataset

I am trying to fit this with a series of gaussians, without overfitting. I have tried the following,

g[x_, xo_, \[Sigma]_, a_] := a Exp[-((x - xo)^2/(2 \[Sigma]^2))]/(\[Sigma] Sqrt[2 \[Pi]]); kvar[k_Integer] := Through[{xo, \[Sigma], a}[k]]; gmodel[n_Integer] := Sum[g[x, Sequence @@ kvar[i]], {i, 1, n}]; gpars[n_Integer] := Flatten@Array[kvar, n]; fitg[data_, maxn_Integer] := MinimalBy[ Table[{#, #["AIC"]} &@ NonlinearModelFit[data, gmodel[n], gpars[n], x], {n, maxn}], Last][[1, 1]]; 

This does not work, as the peaks I am trying to fit are positioned nowhere close to the default starting point of 1. How do I implement a couple of "guesses" as to the positions of the peaks (i.e. a starting point for xo in the gaussian fitting).

Or is this not a good approach? Some background: this is an infrared spectrum, and this is only a part of the whole dataset.

I have the following dataset: enter link description here

I am trying to fit this with a series of gaussians, without overfitting. I have tried the following,

g[x_, xo_, \[Sigma]_, a_] := a Exp[-((x - xo)^2/(2 \[Sigma]^2))]/(\[Sigma] Sqrt[2 \[Pi]]); kvar[k_Integer] := Through[{xo, \[Sigma], a}[k]]; gmodel[n_Integer] := Sum[g[x, Sequence @@ kvar[i]], {i, 1, n}]; gpars[n_Integer] := Flatten@Array[kvar, n]; fitg[data_, maxn_Integer] := MinimalBy[ Table[{#, #["AIC"]} &@ NonlinearModelFit[data, gmodel[n], gpars[n], x], {n, maxn}], Last][[1, 1]]; 

This does not work, as the peaks I am trying to fit are nowhere close to 1. How do I implement a couple of "guesses" as to the positions of the peaks (i.e. a starting point for xo in the gaussian fitting).

Or is this not a good approach? Some background: this is an infrared spectrum, and this is only a part of the whole dataset.

I have the following dataset: dataset

I am trying to fit this with a series of gaussians, without overfitting. I have tried the following,

g[x_, xo_, \[Sigma]_, a_] := a Exp[-((x - xo)^2/(2 \[Sigma]^2))]/(\[Sigma] Sqrt[2 \[Pi]]); kvar[k_Integer] := Through[{xo, \[Sigma], a}[k]]; gmodel[n_Integer] := Sum[g[x, Sequence @@ kvar[i]], {i, 1, n}]; gpars[n_Integer] := Flatten@Array[kvar, n]; fitg[data_, maxn_Integer] := MinimalBy[ Table[{#, #["AIC"]} &@ NonlinearModelFit[data, gmodel[n], gpars[n], x], {n, maxn}], Last][[1, 1]]; 

This does not work, as the peaks I am trying to fit are positioned nowhere close to the default starting point of 1. How do I implement a couple of "guesses" as to the positions of the peaks (i.e. a starting point for xo in the gaussian fitting).

Or is this not a good approach? Some background: this is an infrared spectrum, and this is only a part of the whole dataset.

Source Link

Fitting many peaks to dataset

I have the following dataset: enter link description here

I am trying to fit this with a series of gaussians, without overfitting. I have tried the following,

g[x_, xo_, \[Sigma]_, a_] := a Exp[-((x - xo)^2/(2 \[Sigma]^2))]/(\[Sigma] Sqrt[2 \[Pi]]); kvar[k_Integer] := Through[{xo, \[Sigma], a}[k]]; gmodel[n_Integer] := Sum[g[x, Sequence @@ kvar[i]], {i, 1, n}]; gpars[n_Integer] := Flatten@Array[kvar, n]; fitg[data_, maxn_Integer] := MinimalBy[ Table[{#, #["AIC"]} &@ NonlinearModelFit[data, gmodel[n], gpars[n], x], {n, maxn}], Last][[1, 1]]; 

This does not work, as the peaks I am trying to fit are nowhere close to 1. How do I implement a couple of "guesses" as to the positions of the peaks (i.e. a starting point for xo in the gaussian fitting).

Or is this not a good approach? Some background: this is an infrared spectrum, and this is only a part of the whole dataset.