s_lin_pca Subroutine

public subroutine s_lin_pca(x, nd, nv, pc, ev, ew, r2)

Principal Component Analysis (PCA). It is a special (simplified) case of EOF analysis offered as a separate procedure for clarity/familiarity. It calls s_lin_eof with equal weights.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x(nd,nv)

input data

integer(kind=i4), intent(in) :: nd

number of rows

integer(kind=i4), intent(in) :: nv

number of columns

real(kind=wp), intent(out) :: pc(nd,nv)

principal components

real(kind=wp), intent(out) :: ev(nv,nv)

eigenvectors (unweighted)

real(kind=wp), intent(out) :: ew(nv)

eigenvalues

real(kind=wp), intent(out), optional :: r2(nv)

explained variance (fraction)


Calls

proc~~s_lin_pca~~CallsGraph proc~s_lin_pca s_lin_pca proc~s_err_print s_err_print proc~s_lin_pca->proc~s_err_print proc~s_lin_eof s_lin_eof proc~s_lin_pca->proc~s_lin_eof proc~s_lin_eof->proc~s_err_print eigh eigh proc~s_lin_eof->eigh proc~f_sts_mean_core f_sts_mean_core proc~s_lin_eof->proc~f_sts_mean_core proc~f_sts_std_core f_sts_std_core proc~s_lin_eof->proc~f_sts_std_core proc~f_sts_var_core f_sts_var_core proc~f_sts_std_core->proc~f_sts_var_core proc~f_sts_var_core->proc~f_sts_mean_core

Called by

proc~~s_lin_pca~~CalledByGraph proc~s_lin_pca s_lin_pca interface~fsml_pca fsml_pca interface~fsml_pca->proc~s_lin_pca

Source Code

subroutine s_lin_pca(x, nd, nv, pc, ev, ew, r2)

! ==== Description
!! Principal Component Analysis (PCA).
!! It is a special (simplified) case of EOF analysis offered as a separate
!! procedure for clarity/familiarity. It calls `s_lin_eof` with equal weights.

! ==== Declarations
  integer(i4), intent(in)            :: nd        !! number of rows
  integer(i4), intent(in)            :: nv        !! number of columns
  real(wp)   , intent(in)            :: x(nd,nv)  !! input data
  real(wp)   , intent(out)           :: pc(nd,nv) !! principal components
  real(wp)   , intent(out)           :: ev(nv,nv) !! eigenvectors (unweighted)
  real(wp)   , intent(out)           :: ew(nv)    !! eigenvalues
  real(wp)   , intent(out), optional :: r2(nv)    !! explained variance (fraction)
  real(wp)                           :: wt(nv)    !! simple column weights

! ==== Instructions

  ! ---- handle input

  ! check matrix dimensions
  if (nd .lt. 2 .or. nv .lt. 1) then
     ! write error message and stop if invalid
     call s_err_print(fsml_error(3))
     error stop
  endif

  ! ---- conduct analysis

  ! set weights to 1
  wt = 1.0_wp

  ! call EOF procedure with simple weights and specify use of covariance matrix (opt=0)
  if (present(r2)) then
     call s_lin_eof(x, nd, nv, pc=pc, eof=ev, ew=ew, opt=0, wt=wt, r2=r2)
  else
     call s_lin_eof(x, nd, nv, pc=pc, eof=ev, ew=ew, opt=0, wt=wt)
  endif

end subroutine s_lin_pca