R/effect_anova_rnd.R

Defines functions effect_anova_rnd

effect_anova_rnd = function(args){
  #select x
  mm = args$mm
  assign = attr(mm,"assign")
  select_x = assign==args$i
  select_within = assign == (args$link[3,args$i])

  ##zmat
  z = khatrirao(a = args$mm_id, b = mm[,select_within,drop=F])
  z = qr.resid(qr(mm),z)
  qr_z = qr(z)

  qr_d = qr(mm[,!select_x,drop=F])
  rdx = qr.resid(qr_d,mm[,select_x,drop=F])


  qr_rdx = qr(rdx)
  qr_rdz = qr(qr.resid(qr_d,z))

  SSn = sum(qr.fitted(qr_rdx,args$y)^2)
  SSd = sum(qr.fitted(qr_rdz,args$y)^2)

  MSEn = SSn/ qr_rdx$rank
  MSEd = SSd/ qr_rdz$rank

  Fstat = MSEn/MSEd

  out= c(SSn = SSn, dfn = qr_rdx$rank,
         SSd = SSd, dfd = qr_rdz$rank,
         MSEn = MSEn, MSEd = MSEd,
         'F' = Fstat, 'parametric P(>F)' = 1-pf(q =Fstat, df1 = qr_rdx$rank, df2 =qr_rdz$rank))
  out
}

Try the permuco package in your browser

Any scripts or data that you put into this service are public.

permuco documentation built on June 30, 2022, 9:05 a.m.