corspec               package:seewave               R Documentation

_C_r_o_s_s-_c_o_r_r_e_l_a_t_i_o_n _b_e_t_w_e_e_n _t_w_o _f_r_e_q_u_e_n_c_y _s_p_e_c_t_r_a

_D_e_s_c_r_i_p_t_i_o_n:

     This function tests the similarity between two frequency spectra
     by returning their maximal correlation and the frequency shift
     related to it.

_U_s_a_g_e:

     corspec(x, y, range, plot = TRUE, plotval = TRUE,
     method = "spearman", col = "black", colval = "red",
     cexval = 1, fontval = 1, xlab = "Frequency (kHz)",
     ylab = "Coefficient of correlation (r)", ...)

_A_r_g_u_m_e_n_t_s:

       x: a first data set resulting of a spectral analysis obtained
          with 'spec' or 'meanspec' (not in dB).

       y: a second data set resulting of a spectral analysis obtained
          with 'spec' or 'meanspec' (not in dB).

   range: range of 'x' and 'y' (in kHz).

    plot: logical, if 'TRUE' plots r values against frequency shift (by
          default 'TRUE').

 plotval: logical, if 'TRUE' adds to the plot maximum r value and
          frequency offset (by default 'TRUE').

  method: a character string indicating which correlation coefficient
          is to be computed ("pearson", "spearman", or "kendall") (see
          'cor').

     col: colour of r values.

  colval: colour of r max and frequency offset values.

  cexval: character size of r max and frequency offset values.

 fontval: font of r max and frequency offset values.

    xlab: title of the frequency axis.

    ylab: title of the r axis.

     ...: other 'plot' graphical parameters.

_D_e_t_a_i_l_s:

     It is important not to have data in dB.
      Successive correlations between 'x' and 'y' are computed when
     regularly shifting 'y' towards lower or higher frequencies.
      The maximal correlation is obtained at a particular shift
     (frequency offset).  This shift may be positive or negative.
      The corresponding p value, obtained with 'cor.test', is plotted.
      Inverting 'x' and 'y' may give slight different results, see
     examples.

_V_a_l_u_e:

     If 'plot' is 'FALSE', 'corspec' returns a list containing four
     components: 

       r: the successive correlation values between 'x' and 'y'.

    rmax: the maximum correlation value between 'x' and 'y'.

       p: the p value corresponding to 'rmax'.

       f: the frequency offset corresponding to 'rmax'.

_A_u_t_h_o_r(_s):

     Jrme Sueur jerome.sueur@ibaic.u-psud.fr

_R_e_f_e_r_e_n_c_e_s:

     Hopp, S. L., Owren, M. J. and Evans, C. S. (Eds) 1998. _Animal
     acoustic  communication_. Springer, Berlin, Heidelberg.

_S_e_e _A_l_s_o:

     'spec', 'meanspec', 'corspec', 'covspectro', 'cor', 'cor.test'.

_E_x_a_m_p_l_e_s:

     data(tico)
     # compare the two first notes spectra
     a<-spec(tico,f=22050,wl=512,at=0.2,plot=FALSE)
     c<-spec(tico,f=22050,wl=512,at=1.1,plot=FALSE)
     op<-par(mfrow=c(2,1), mar=c(4.5,4,3,1))
     spec(tico,f=22050,wl=512,at=0.2,col="blue",type="l")
     par(new=TRUE)
     spec(tico,f=22050,wl=512,at=1.1,col="green",type="l")
     legend(x=8,y=0.5,c("Note A", "Note C"),lty=1,col=c("blue","green"),bty="o")
     par(mar=c(5,4,2,1))
     corspec(a,c,range=c(0,11.025),type="l",
       ylim=c(-0.25,0.8),xaxs="i",yaxs="i",las=1)
     par(op)
     # different correlation methods give different results...
     op<-par(mfrow=c(3,1))
     corspec(a,c,range=c(0,11.025),
       type="l",xaxs="i",las=1, ylim=c(-0.25,0.8))
     title("spearmann correlation (by default)")
     corspec(a,c,range=c(0,11.025),
       type="l",xaxs="i",las=1,ylim=c(0,1),method="pearson")
     title("pearson correlation")
     corspec(a,c,range=c(0,11.025),
       type="l",xaxs="i",las=1,ylim=c(-0.23,0.5),method="kendall")
     title("kendall correlation")
     par(op)
     # inverting x and y does not give exactly similar results
     op<-par(mfrow=c(2,1),mar=c(2,4,3,1))
     corspec(a,c,range=c(0,11.025),type="l")
     corspec(c,a,range=c(0,11.025),type="l")
     par(op)

