Interaction estimation i R for Conjoint Analysis
0
0
Entering edit mode
Marcin ▴ 10
@marcin-3415
Last seen 9.8 years ago
Hi, here is a source code that allows estimate interactions for Conjoint Analysis in R. Obtained matrix xInteractions can be applied as input in partutilities (part-worth utility estimation) or others that can be obtained from: http://keii.ae.jgora.pl/nauka/procedury.zip. subsets <- function(n, r) { if(is.numeric(n) & length(n) == 1) v <- 1:n else { v <- n n <- length(v) } subs <- function(n, r, v) if(r <= 0) NULL else if(r >= n) matrix(v[1:n], nrow = 1) else rbind(cbind(v[1], subs(n - 1, r - 1, v[-1])), subs(n - 1, r , v[-1])) subs(n, r, v) } # function subsets by: # Bill Venables # CSIRO Laboratories # PO Box 120, Cleveland, 4163 # AUSTRALIA interval<-function(x,begins){ output<-length(begins) for(i in 1:(length(begins)-1)){ if((begins[i]<=x) && (x<begins[i+1])){ output<-i="" }="" }="" output="" }="" allowed="" <-function(indexes,begins){="" resul<-true="" for(i="" in="" 1:(length(indexes)-1))="" for(j="" in="" (i+1):length(indexes)){="" if(interval(indexes[i],begins)="=interval(indexes[j],begins))resul&lt;-F" alse="" }="" resul="" }="" x<-as.matrix(x)="" numvariables<-ncol(x)="" interlevels<-2="" maxcomb<-interlevels+1="" levels<-c(2,1,1)="" begins<-seq(along.with="levels)" begins[1]<-1="" for(i="" in="" 2:length(levels)){="" begins[i]<-begins[i-1]+levels[i-1]="" }="" xinterakcje<-x="" for(i="" in="" 1:interlevels){="" for(j="" in="" 1:nrow(subsets(numvariables,i+1))){="" indexes<-subsets(numvariables,i+1)[j,]="" print(paste(paste(indexes,collapse="," ),allowed(indexes,begins)))="" if(allowed(indexes,begins)){="" output<-x[,indexes[1]]="" for(k="" in="" 2:(i+1)){="" output<-output*x[,indexes[k]]="" }="" xinterakcje<-cbind(xinterakcje,output)="" }="" }="" }="" nam<-paste("x",1:numvariables,sep="" )="" for(i="" in="" 1:interlevels){="" for(j="" in="" 1:nrow(subsets(numvariables,i+1))){="" indexes<-subsets(numvariables,i+1)[j,]="" if(allowed(indexes,begins)){="" nam<-c(nam,paste(paste("x",indexes,sep="" ),collapse="_" ))="" }="" }="" }="" colnames(xinterakcje)<-nam="" print(xinterakcje)="" x<-as.data.frame(xinterakcje)="" best="" regards,="" marcin="" [[alternative="" html="" version="" deleted]]="" <="" div="">
• 758 views
ADD COMMENT

Login before adding your answer.

Traffic: 860 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6