Hello, everyone,
I am trying to write a Perl script to identify straighlining behavior with grid questions. In total I have three grid questions called...
ItemsIdentity
ItemsAttitudes
ItemsAttitudes2
with six, ten and six questions. Now I wanna know if a respondent always picks the same answer on a seven point Likert-scale. If he or she does, then there is zero variance in the answers.
Now, my script looks like this:
[% Begin Unverified Perl
# Exercises
my @exername = ("ItemsIdentity_r", "ItemsAttitudes_r", "ItemsAttitudes2_r");
my @exernums = (6, 10, 6);
my $nScales = scalar @exername
# Calculate the mean
my @answers = ();
my $j=1;
for (my $k = 1; $k <= $nScales; $k++) {
for (my $i = 1; $i <= $exernums[k]; $i++) {
$answers[j] = GETVALUE($exername[k]) . $i;
j=j+1;
}
}
my $answers_mean = mean(@answers)
# Check for straightlining behavior
$straightliner = 0;
$sqtotal = 0;
foreach (@$answers) {
$sqtotal += ($_ - $answers_mean) ** 2
}
if ( $sqtotal==0 ) {
$straightliner = 1;
}
SET("SetStraightliner_Dummy",$straightliner);
End Unverified %]
The idea is to loop over the questions and see, if the answers deviate from the mean of the respondent's answers.
A somewhat simpler approach could be to simply take a look at the answers [2...end]. If they all don't differ from the first answer, this is obviously a straightliner. But I like my approach a bit more, because it allows to decide on how much straightlining (=the degree of variance) is accepted.
Unfortunately, I am completely new to Perl Script and don't know what goes wrong. I only get an error message when running the script in the test mode.
I am looking forward to your help. :-)