How to determine whether the differences between two time series are significant (in R)?

There are two time series, that are generated in an experiment, where the intensity of signals of chemical bounds are measured along a wavelength interval, but the second series are generated by measuring the intensity of radiated sample of chemical bound in the same interval. Two experiments are conducted and the results graphed. Plots indicate that in some intervals there are differences in signal intensity between the radiated and non radiated samples ( that would indicate changes of the chemical bound due to radiation). One experiment shows that these differences are greater whilst the other shows almost neglible differences. How could I compare these series in order to test the significance of the differences along the wavelength interval. And if these differences are significant then even maybe construct some sort of function that could express these differences theoretically?
I tried to do the t test in R comparing the signal intensity on each wavelength between the time series that correspond to non-radiated chemical bound signal intensity and the other time series that fixes the signal intensity for radiated sample chemical bound along the wavelength interval. ( Here I take wavelengths as an independent variable (time) and the signal intensity is the dependent variable. When I executed the t test in R for radiated and non radiated intensities it showed that there is a significant difference in means so that could conclude that the time series do differ. I am not sure how strong the t test would be though in this instance. Furthermore I would like to somehow measure the difference. I also tried the cor(x,y) function in R and it showed very high correlation 0.99 so I think that's not at all reliable too, maybe it shows high correlation only because they are both dependent on time (wavelength) and the time variable distorts the correlation. Anyway any ideas would be helpful!

So, in a nutshell, I want to know whether some factor ( in this case radiation) have a significant impact on output ( that is the values of these series). When looking at graphs it looks that these differences appear on certain wavelength intervals ( that would indicate that the chemical bound has been changed by radiation). Maybe one can even compute some sort of function that expresses the changes? Any help would be greatly appreciated!

When applying the gam function in R I get a warning message:

Warning message: In model.matrix.default(mt, mf, contrasts) :
non-list contrasts argument ignored

In the first experiment the difference in residual deviance between the radiated - non-radiated sample is around 9.18. In the second experiment the difference is around 17.87. When I don't wrap up the predicator $$t$$ with $$s$$ I get larger residual deviance.

A t-test only compares the means of two groups. If you want to study relation of two continious variables you would do a regression (for example, y~x1+bx2). However, I assume the relationship between your response variable (y = intensity) and predictor (x=wavelength) for both your experiments (experiment in your case is another predictor (x) but this one is categorical: a factor with 2 levels; if you’d have 3 experiments, the factor “experiment” would have 3 levels) is not linear, so it has some kind of wave shape, right? You can test the difference between the two non-linear curves with a Generalized Additive Model (GAM). In R, you have to put a wrapper s() around your non-linear predictor. So it would be something like gam(intensity ~ s(wavelength) + Experiment). Do you have to consider more variables than these?

• Thank you so much for replying! How do you determine that the experiment would not be linear? ( If you mean the shape of the graphs where t - wave number and x(t) - intensity, then yes they are non-linear). I don't understand how could I possible make a variable "experiment"? I only have a wave numbers and corresponding intensity. On each experiment intensity is measured of non-radiated sample and then radiated sample. I have two experiments.
– user
May 10, 2020 at 19:25
• @MatjeLM And I want to deduct from this information whether the differencein intensity between the radiated and non radiated samples are significant ( bare in mind that the significant difference is only visible in particular wavelength interval) and possible express the difference with some function. So, I don't really have any "experiment", so am not sure how to proceed.
– user
May 10, 2020 at 19:27
• @MatjeLM When applying the gam function I get a warning message that I posted on OP. There are differences in residual deviances between non-radiated and radiated samples, on second experiment the difference is larger ( as expected because on second experiment the difference between radiated and non radiated sample intenisty is largen in certain wavelength intervals.) By the way experiments by themselves don't differ in the way they are conducted, the results just show that there could be differences in intensity between R and Non R samples.
– user
May 10, 2020 at 19:36

The gam method might be a little advanced, but it is a great tool to analyse non-linear relationships between y ~ x. In your case you are not only interested in that particular relationship in one scenario (experiment), but in two. So, you get 2 non-linear curves that each describe one experiment.

Is that true?

If that is your purpose, you can create a new column in your dataset (right next to your intensity and wavelength columns) that says “Experiment”. Then you label your experiments as for example “Exp1”and “Exp2” and put the correct labels in each row of observations (so you end up with a lot of the same labels, because you need to tag each observation.

Now, that I read your 2nd comment I am doubting: the curves are not continous then? GAM are good for comparing non-linear curves, but maybe your data needs a different approach. Would it be possible to show a graph of some of your data?