code: def p_tests(
      z: Float64Array, lag: int, trend: UnitRootTrend
  ) -> tuple[float, float]:
      x, y = z[:, 1:], z[:, 0]
      nobs = int(x.shape[0])
      x = add_trend(x, trend=trend)
      beta = lstsq(x, y, rcond=None)[0]
      u = y - x @ beta
      z_lead = z[1:]
      z_lag = add_trend(z[:-1], trend=trend)
      phi = lstsq(z_lag, z_lead, rcond=None)[0]
      xi = z_lead - z_lag @ phi
  
      omega = xi.T @ xi / nobs
      for i in range(1, lag + 1):
          w = 1 - i / (lag + 1)
          gamma = xi[i:].T @ xi[:-i] / nobs
          omega += w * (gamma + gamma.T)
      omega21 = omega[0, 1:]
      omega22 = omega[1:, 1:]
      omega112 = float(
          omega[0, 0] - np.squeeze(omega21.T @ inv(omega22) @ omega21)
      )
      denom = u.T @ u / nobs
      p_u = nobs * omega112 / denom
  
      tr = add_trend(nobs=z.shape[0], trend=trend)
      if tr.shape[1]:
          z = z - tr @ lstsq(tr, z, rcond=None)[0]
      else:
          z = z - z[:1]  # Recenter on first
      m_zz = z.T @ z / nobs
      p_z = nobs * float((omega @ inv(m_zz)).trace())
      return p_u, p_z
  
imports: import argparse
  import datetime
  import gzip
  import os
  import pickle
  from random import shuffle
  import sys
  from typing import IO, Optional, cast
  import colorama
  from joblib import Parallel, delayed
  import numpy
  from numpy.linalg import inv, lstsq, solve
  import pandas
  from phillips_ouliaris import QUANTILES, ROOT, SAMPLE_SIZES, TRENDS
  import psutil
  from arch.typing import Float64Array, Literal, UnitRootTrend
  from arch.utility.timeseries import add_trend
label_desc: Use image node_id 6 for calling a global function with example usage: p_tests(z, lag, trend) and returns: p_u,  p_z