Recovering embedded data from seed value

34 Views Asked by At

I recently re-ran a conjoint experiment in Qualtrics using code from 2021 which seems to be no longer compatible with Qualtrics (see post here). Unfortunately, the embedded data for the traits within my code did not save (although this has previously worked with the same survey code in the past). The embedded seed values did save (seed1-seed5) for each respondent.

I believe I can still recover the randomized attributes provided to respondents given the seed values and JavaScript code. However, I am not sure how to do this. The code is below. I am most fluent in R, and am wondering if there is a way to sync R and a JavaScript file to run the below chunk of code in JavaScript for my list of seed values, and save the corresponding trait combinations as another object.

Any insight on how to recover these values would be greatly appreciated.

The code below is just a sample of for the 5th conjoint profile. This was run five times, with five different seeds, and correspondingly five different trait pairs (traits1a + traits1b …. traits5a + traits5b)

Qualtrics.SurveyEngine.addOnload(function() {     !function(a,b){function c(c,j,k){var n=[];j=1==j?{entropy:!0}:j||{};var s=g(f(j.entropy?[c,i(a)]:null==c?h():c,3),n),t=new d(n),u=function(){for(var a=t.g(m),b=p,c=0;q>a;)a=(a+c)*l,b*=l,c=t.g(1);for(;a>=r;)a/=2,b/=2,c>>>=1;return(a+c)/b};return u.int32=function(){return 0|t.g(4)},u.quick=function(){return t.g(4)/4294967296},u["double"]=u,g(i(t.S),a),(j.pass||k||function(a,c,d,f){return f&&(f.S&&e(f,t),a.state=function(){return e(t,{})}),d?(b[o]=a,c):a})(u,s,"global"in j?j.global:this==b,j.state)}function d(a){var b,c=a.length,d=this,e=0,f=d.i=d.j=0,g=d.S=[];for(c||(a=[c++]);l>e;)g[e]=e++;for(e=0;l>e;e++)g[e]=g[f=s&f+a[e%c]+(b=g[e])],g[f]=b;(d.g=function(a){for(var b,c=0,e=d.i,f=d.j,g=d.S;a--;)b=g[e=s&e+1],c=c*l+g[s&(g[e]=g[f=s&f+b])+(g[f]=b)];return d.i=e,d.j=f,c})(l)}function e(a,b){return b.i=a.i,b.j=a.j,b.S=a.S.slice(),b}function f(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(f(a[c],b-1))}catch(g){}return d.length?d:"string"==e?a:a+"\0"}function g(a,b){for(var c,d=a+"",e=0;e<d.length;)b[s&e]=s&(c^=19*b[s&e])+d.charCodeAt(e++);return i(b)}function h(){try{if(j)return i(j.randomBytes(l));var b=new Uint8Array(l);return(k.crypto||k.msCrypto).getRandomValues(b),i(b)}catch(c){var d=k.navigator,e=d&&d.plugins;return[+new Date,k,e,k.screen,i(a)]}}function i(a){return String.fromCharCode.apply(0,a)}var j,k=this,l=256,m=6,n=52,o="random",p=b.pow(l,m),q=b.pow(2,n),r=2*q,s=l-1;if(b["seed"+o]=c,g(b.random(),a),"object"==typeof module&&module.exports){module.exports=c;try{j=require("crypto")}catch(t){}}else"function"==typeof define&&define.amd&&define(function(){return c})}([],Math);  
       
 // seed random number generator from embedded data fields     
// conjoint profile 5     
Math.seedrandom('${e://Field/seed5}');  
        
// Create Variables for Traits associated with each dimension.   

var vsex = ["Female", "Male"];    var vrace = ["Black", "White"];     
var vtax = ["Supports raising revenue via increases in sales taxes", "Supports raising new revenue via increases in income tax"];      
var vpubsec = ["Supports cracking down on crime through increased investment in the local police, more police in the streets, and increasing penalties for violent crimes", "Supports addressing the root causes of crime via investment in community programs, jobs training for prisoners, and investment in police-alternative responses (e.g., psychological support) to 911 calls"]; 
var vedu = ["Supports increasing investment in charter schools and programs that enable school choice among parents", "Supports increasing public school funding without corresponding increase in funding for privatized charter schools"];          



// Use math.random to randomly select traits for each dimension for candidate A     
traits_a = [                 vsex[Math.floor(Math.random()*vsex.length)],       vrace[Math.floor(Math.random()*vrace.length)],                 vtax[Math.floor(Math.random()*vtax.length)],                 vpubsec[Math.floor(Math.random()*vpubsec.length)],                  vedu[Math.floor(Math.random()*vedu.length)]];                          

// Use math.random to randomly select traits for each dimension for candidate B

traits_b = [                 vsex[Math.floor(Math.random()*vsex.length)],       vrace[Math.floor(Math.random()*vrace.length)],                 vtax[Math.floor(Math.random()*vtax.length)],                 vpubsec[Math.floor(Math.random()*vpubsec.length)],                  vedu[Math.floor(Math.random()*vedu.length)]];          
// Create list of variables to use when setting attributes     
a_list = ["a1","a2","a3","a4","a5"];      
b_list = ["b1","b2","b3","b4","b5"]; 

    // set html values in conjoint table     

for(i=0;i<6;i++){         document.getElementById(a_list[i]).innerHTML = traits_a[i];         document.getElementById(b_list[i]).innerHTML = traits_b[i];     }
    
    // store values as embedded data fields     
Qualtrics.SurveyEngine.setEmbeddedData('traits5a', traits_a.join("|"));     Qualtrics.SurveyEngine.setEmbeddedData('traits5b', traits_b.join("|"));

});

I have not been able to run the JavaScript code outside of the Qualtrics environment yet.

0

There are 0 best solutions below