R/yXn.R

Defines functions yXn

Documented in yXn

yXn <- 
  function(response, group, subgroup) {
	  n <- length(response)
	  gr <- unique(group)
	  ngr <- length(gr)
	  Nsgr <- length(unique(group*n + subgroup))
	  X <- NULL
	  y <- NULL
	  nfillsgr <- 0
	  for (i in 1:ngr) {
		  sgr <- unique(subgroup[group==gr[i]])
		  nsgr <- length(sgr)
		  for (j in 1:nsgr) {
			  yij <- response[group==gr[i]&subgroup==sgr[j]]
			  y <- c(y,yij)
			  nij <- length(yij)
			  xij <- c(1, rep(0, (ngr+Nsgr)))
			  xij[1+i] <- 1
			  xij[1+ngr+nfillsgr+j] <- 1
			  X <- rbind(X, rep(1,nij)%*%t(xij))
	  	}
	  	nfillsgr <- nfillsgr + nsgr
  	}
  	return(list(y, X))
  }

Try the lmreg package in your browser

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

lmreg documentation built on May 2, 2019, 9:29 a.m.