allinteract.fun_function(x.mat){ ## this function gives all main effects and all 2-way interactions ## for a set of X variables. ## x.mat is a cbind() of the x vars. ## command for the discrim data: x.mat.allinteract <- allinteract.fun(cbind(senior,age,educ,exper)) ## will produce a dataframe with the following columns: ## ## > > names(x.mat.allinteract) ## "senior" "age" "educ" "exper" "senior.age" "senior.educ" ## "senior.exper" "age.educ" "age.exper" "educ.exper" x.mat_data.frame(x.mat) interact.mat_NULL interact.names_NULL for (i in 1:(dim(x.mat)[2]-1)){ for (j in (i+1):(dim(x.mat)[2])){ interact_x.mat[,i]*x.mat[,j] interact.mat_cbind(interact.mat,interact) interact.names_c(interact.names,paste(names(x.mat)[i],".",names(x.mat)[j],sep="")) } } interact.mat_data.frame(interact.mat) names(interact.mat)_interact.names return(cbind(x.mat,interact.mat)) } ### example commands on discrim dataset: x.mat.allinteract <- allinteract.fun(cbind(senior,age,educ,exper)) ## first 5 lines of resulting dataset > x.mat.allinteract[1:5,] senior age educ exper senior.age senior.educ senior.exper age.educ age.exper 1 96 329 15 14.0 31584 1440 1344.0 4935 4606.0 2 82 357 15 72.0 29274 1230 5904.0 5355 25704.0 3 67 315 15 35.5 21105 1005 2378.5 4725 11182.5 4 97 354 12 24.0 34338 1164 2328.0 4248 8496.0 5 66 351 12 56.0 23166 792 3696.0 4212 19656.0 educ.exper 1 210.0 2 1080.0 3 532.5 4 288.0 5 672.0