Saturday, January 21, 2012

Stats Saturday 1 - MySQL and R

Fig. 1 - QQ-plot of pretest reaction times
I've decided to try and devote my Saturday mornings to working out the technical bits I need for my dissertation - which, at this stage of the project, means stats stats stats.

Although I'm not sure if I'm going to end up using R to do all the stats for my dissertation - but I'm currently using it poke at my dataset a little.

Today I wanted to accomplish two things. I wanted to get R connected to the MySQL database storing all of my raw data, and I wanted to work out how to generate a QQ-plot from that data.

This was all surprisingly easy ...


Step 1 - load the library

MySQL connectivity to R is provided through the CRAN package, rMySQL.
To import the library you merely need to run the command
library(RMySQL)
You shouldn't have any problems unless you haven't actually got the library installed - I had to "apt-get install r-cran-rmysql" under Ubuntu to get it.

Step 2 - get a connection object

Next, we connect to the database and grab a connection object that will be used in subsequent interactions with the DB. We use the command
conn <- dbConnect(MySQL(), user="USER", password="PASSWORD", dbname="DBNAME")
Where "conn" is the connection object, USER is your username, PASSWORD the db password, and DBNAME the name of the database you're trying connecting to (I'm assuming you're connecting to localhost here)

There are a bunch of ways you can set these connections up - check this out (it's a PDF by the way...).

Step 3 - run a query

This part was surprisingly easy - there are a couple of ways you can do this, including stepping through results in stages, but I was just interested in reading the output of a db query into an R dataframe straight.
data <- dbGetQuery(conn,"select ur.user_name,avg(resp_time_per_deg) as resptime \
from tetris4km_mr_test_data as td \
inner join tetris4km_user_roles as ur \
on td.student_number = ur.user_name \
where td.pretest_posttest = 'pretest' and td.reason_excluded is null \
and td.correct_incorrect = 'correct' and td.resp_time_per_deg < 200 \
group by ur.user_name")
The dbGetQuery() function accepts two arguments, the first being our connection we made in step 2, the second being the query itself. In my query here, I'm interested in pulling out my participants' student numbers and their average reaction time on their mental rotation pre-test.
dbGetQuery() then returns a dataframe with our data. We'll use this for our QQ-plot.

Step 4 - do stuff with your data (QQ-plot)

So I wanted to do a QQ-plot of this data to perform a visual test of normality. I simply ran the following commands
qqnorm(data$resptime);qqline(data$resptime)
and got the lovely fig. 1

Tuesday, January 3, 2012

Mental Rotation 1 - Introduction and Discovery

What is "Mental Rotation"?

Fig.1 - trial pairs from
Shepard & Metzler (1971)
The Wikipedia entry on Mental Rotation tells us that the term designates the ability of (certain) animals, including humans, "to rotate mental representations of two-dimensional and three-dimensional objects".

As we will see in this series of posts, this straightforward, even trivial seeming, definition is not necessarily uncontroversial - so, for the moment, it is best to think of "Mental Rotation" as being whatever it is that allows one to look at the pairs of images in Fig. 1 and tell, without manipulating anything in physical space, whether the "object" in the left circle is the same as that in the right.

In this post we will be taking a quick look at the paper that kick-started the study of Mental Rotation and related phenomena.



Shepard and Metzler's 1971 paper  - uncovering the phenomenon

Roger Shepard and Jacqueline Metzler's seminal paper "Mental Rotation of Three-dimensional Objects" is rightly considered to be one of the classics of cognitive psychology because of its beautifully simple design and the implications of its results.

Fig. 2 - Shepard and Metzler's results
Shepard and Metzler (1971) presented their participants (n=8) with pairs of two-dimensional projections of three-dimensional objects such as those in fig.1 above.There were 1600 trials in total, presented in a randomised order. Half of the trials showed the same object in the left and right positions. These projections of the object were rotated, at multiples of 20 degrees, either in the image plane (around the Z axis) or in depth (around the Y axis). The other half of the trials showed different, enantiomorphic, pairs in the left and right positions, similarly rotated in the image plane or in depth.

A tone signalled the start of each trial to the participants, after which the pair of images were revealed and a timer started. The participants were then required to determine whether the objects in the pair of images were the same or different by pulling one of two levers which recorded their response and stopped the timer.

Fig. 2 shows the results of plotting time as a function of angle of rotation between identical images. The top graph shows the results for rotation in the picture plane, while the bottom shows the results for rotation in depth. What is striking about these graphs is their linearity - they show that as the angle of rotation between the two images increased, so did the time taken to recognise if they were the same image. Further, not only did reaction time increase but it increased at a fixed ratio (this is what gives it it's linear shape).

This is the same kind of result one would get if one took two physical (identical) pictures, laid them down next to each other at different angles, and then rotated one of them at a fixed speed until the two images faced the same direction. As you increased the difference in angle between the two images it would take you longer to rotate them until they were both at the same orientation. Incidentally, Shepard and Metzler fixed the average speed of this (mental) rotation to be around 60 degrees per second for their participants.



Importance of work

The biggest impact that Shepard and Metzler's study has most likely had is in the debate around the nature of mental representation, in particular in the debate about whether the nature of our mental representations (assuming there are such structures) are propositional (that is, sentence-like) or image-like (or that are functionally equivalent (Sternberg, 2011) to images).

It has been supposed that, because the relationship between the angle of rotation and reaction time is so strongly linear, there is a continuous, analogue process underlying mental rotation - something reminiscent of the example I gave above of physically rotating a picture at a fixed speed. There are two important things to note here though. First, this does not mean that there are literally pictures in the head being rotated, it only suggests that there is some process that is, like I said above, functionally equivalent to rotating actual images (i.e. they work the same way, they don't have to look the same - this will be explored in more detail in future posts). Second, it doesn't necessarily mean that the subjects are aware that this process is going on - it could be that this rotation of image-like representations is entirely sub-personal or sub-awareness. However, when interviewed, all Shepard and Metzler's subjects reported experiencing some kind of visual imagery which they "rotated" in mind. Of course, as the researchers point out, introspective data is best "interpreted with caution" (Shepard & Metzler, 1971: 701).


References :

Pitt, David, "Mental Representation", The Stanford Encyclopedia of Philosophy (Fall 2008 Edition), Edward N. Zalta (ed.), URL =

Shepard, R. N., & Metzler, J. (1971). Mental rotation of three-dimensional objects. Science, 171(3972), 701-703.

Sternberg, R., & Sternberg, K. (2011). Cognitive Psychology (6th ed.). London: Wadsworth Publishing.

Sunday, January 1, 2012

Restatement of a small part of "Is necrophilia wrong?" by Tauriq Moosa

"Is necrophilia wrong?"

This question is the title of Tauriq Moosa's latest article on bigthink.com. It's an interesting piece which I thoroughly enjoyed reading ... although, as I'm sure Tauriq would agree, the title can be taken as being slightly misleading. A more accurate title may have been something like "Why your answer to the question 'Is necrophilia wrong' probably can't be justified" or "Your intuitions about necrophilia aren't to be trusted" ... something like that.

In his piece Tauriq doesn't actually answer his title question but rather argues that, in the case of necrophilia
There is little reason to think the act automatically wrong. But being unconvinced by the arguments against an act does not mean one automatically supports or encourages it. All that we have done is reflect on arguments and justifications which proclaim necrophilia automatically wrong.
That is to say that his primary aim is not to establish whether the act of having sex with a corpse is morally (im)permissible, but rather to show that the usual ("common sense", knee-jerk, what have you) justifications for saying that it is wrong are unsatisfactory.
I think this is an extremely important point, and I think that this part of Tauriq's argument deserves a restatement in order to get clear about exactly what he is trying to establish here. This is especially important since a number of comments on the article suggest that some readers have been confused by it in spite of it being crystal clear (I suspect that this partly vindicates Tauriq's thoughts about how our disgust reactions cloud our judgement).

The argument

So what is the argument? There are a couple of steps.

Firstly, we should not believe that an act is wrong (or right) without some reason for believing that it is wrong or right, that is, there needs to be some kind of justification supporting our moral beliefs, claims, and judgements.
Now, it may seem that this is such a basic point that it need not be articulated, but it actually plays a very important role below, so it deserves just a little attention. A lot of work in meta-ethics concerns just what kind of justifications suffice to underwrite our moral claims, but - regardless of how that debate eventually gets settled - the most important thing to note is that anyone who makes a moral claim, or holds some kind of moral belief, will justify it in some way. This may take the form of an appeal to a God, to Reason, to a moral calculus, to societal norms, or whatever - in this point we're not concerned with the quality or success of the justifications, just with the fact that they're pretty much always in play.

Secondly, Tauriq thinks that the standard justifications of the belief that necrophilia is wrong don't actually stand up to scrutiny - this is really the core, and bulk, of the argument. These "standard justifications" are (1) the notion that there is something intrinsically special about the human body that makes it sacred/inviolable thus rendering necrophilia intrinsically/automatically wrong. (2) there is something about the (moral?) disgust that we feel towards necrophilia that makes the act intrinsically wrong. (3) a weaker argument that sex with corpses poses a health risk and is therefore wrong (he briefly mentions a fourth - finding it is left as an exercise for the reader).
I wont rehash the arguments that Tauriq gives against these three points, the original article does a bang-up job at doing that. What is important to note here is that in order for this second step in the argument to work it is imperative that (a) it covers all the most commonly used arguments against necrophilia and (b) that the arguments against points 1-3 actually do show them to be inadequate as justifications for the claim that sex with a corpse is wrong. I think that the article manages (a) quite nicely, and - given the context in which the piece appears - I believe (b) to be pretty well established too.


Thirdly, and finally, we can now turn to the question of the moral status of necrophilia. On the one hand we have the idea that we need to be able to justify our moral claims. On the other hand, we see that the common justifications for claiming that necrophilia is automatically wrong don't actually do the job of justifying that claim. And it is here, at this point, that people seem to have gotten confused.
Pointing out that a justification fails to pass muster doesn't thereby commit one to some position regarding the truth value of a statement like "necrophilia is automatically wrong". For example, let's imagine a situation where Manchester United was going to play a (genuine) game against the Amanzimtoti under-8-year-old's soccer team. Let's then say that one of my friends claims that "Manchester United is going to beat Amanzimtoti under 8's in soccer" and I ask him to justify this claim. Let's further imagine that he then goes on to say "Well, Manchester United always win when I eat pizza for lunch, and I've eaten pizza for lunch, so they'll win". This is a mad justification for his belief, and I tell him as much - it goes no way towards establishing the truth of his claim. But, having rejected the justification he has offered, I'm not thereby committing myself to the falsity of his claim, in fact, I think it's fair to say that Man.U would cream the Toti under 8's and my justification for this would be because they're an professional soccer team made up of adults! I can (and do) agree with the claim itself, but not the justification.
It's the same thing with Tauriq's argument - he's pointing out that these justifications are shabby and aren't adequate to establish what they're meant to, not that he thinks that necrophilia is right!
It might be that there is an answer to the question "is necrophilia right?", it might also turn out that that answer is "no, it's intrinsically wrong". But the standard justifications given for that answer don't manage to establish that - the question of the moral status of necrophilia remains unsettled given these justifications.

** Edit - Reply from Tauriq Moosa **

Thanks to Tauriq for the following response:


Thanks for this. 

I should clarify that I'm in two minds about ideas of right and wrong. On the one hand, I don't think anything morally interest is, by definition, right or wrong: otherwise, there's no moral discussion. For example, if we define murder as morally wrong killing, then there's no discussion. It's wrongness is in the title. However, killing, the neutral term, can be right and wrong - depending on circumstances, consequences, etc.

On the other hand, I'm more and more convinced by the ideas of objectivity in ethics: that there are things that are right and wrong. Or rather, that morality is not subjective at all: that, if we term something wrong, then it IS wrong (by whatever moral framework we're focused on). In other words, I'm becoming more and more convinced that Hume's Guillotine is blunt. 

Thus necrophilia might be neither right or wrong, by definition. I think there ARE cases where it is wrong - but then it comes down to property violation, only instantiating that necrophilia is not wrong. I can't fathom that ONLY having sex with dead bodies is wrong, since, like killing, we must further investigate the surrounding moral environment. So I don't think necrophilia is wrong and I don't think there are any arguments that have been made to counter that, though I hope someone does create one.