<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Arial","sans-serif";
        color:windowtext;
        font-weight:normal;
        font-style:normal;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Arial","sans-serif";
        color:#1F497D;
        font-weight:normal;
        font-style:normal;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:#1F497D;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="Section1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hello everybody,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I've got some code which runs wilcoxon tests for each 'year' and 'hotspot_ID' combination from my data. It basically compares the densities each hotspot_Id with the densities in hotspot 0 (one of the hotspot_ID's which means 'everywhere
 else that is not in a hotspot') – some test data is attached. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It looks like this. It gives me a nice, and very big, word document with all the tests in there. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">d<-read.csv("F:\\Offshore_analysis1_(UK_wide_approach)<a href="file:///\\Extra_analyses\test_regularity_without_nim_numbers\3_data_for_R\6360_wn.csv">\\Extra_analyses\\test_regularity_without_nim_numbers\\3_data_for_R\\6360_wn.csv</a>",
 header=T)</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif""> </span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif""># all tests between 0 and the other groups within each year together</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">for(i in 1980:2005){</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">    for(j in 1:34){</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        tmp<- d[d$YEAR == i & d$hotspot_ID %in% c(0, j), ]</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        print(c(i, j))</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        try(print(wilcox.test(DENSITY~factor(hotspot_ID), data= tmp, na.action = na.omit)))</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">    }</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">}</span><o:p></o:p></p>
<p><span style="font-family:"Arial","sans-serif""> </span><o:p></o:p></p>
<p><o:p> </o:p></p>
<p class="MsoNormal">Note that many of these did not run as there is not data for every combination of year and hotspot. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I want to be able to quickly extract which combinations ran, and of those, which had a P value less than some threshold, lets say 0.05. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So I'd like to extract some kind of table or ideally a .csv file with 3 columns:<o:p></o:p></p>
<p class="MsoNormal">Year, Hotspot_ID, P-value. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My attempts at altering the code to do that are here.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">d<-read.csv("F:\\offshore_SPAs\\1_Stage1\\2_analysis_GL1.4\\2_UK_wide\\3_data_for_R.\\220_br.csv", header=T)</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif""> </span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif""># all tests between 0 and the other groups within each year together</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">  output.2<-matrix( ncol=3, nrow=3000)</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif""> </span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">for(i in 1980:2005){</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">    for(j in 1:34){</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        tmp<- d[d$YEAR == i & d$hotspot_ID %in% c(0, j), ]</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        print(c(i, j))</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        try(wt<-(wilcox.test(DENSITY~factor(hotspot_ID), data= tmp, na.action = na.omit)</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        )</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">        output.2$p<-wt$p.value)</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">      }</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">}</span><o:p></o:p></p>
<p style="margin-left:72.0pt"><span style="font-family:"Arial","sans-serif"">      </span><o:p></o:p></p>
<p><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I've played around quite a bit with the placement of the output bits, <o:p></o:p></p>
<p class="MsoNormal">I'm hoping someone can spot either where I'm going wrong with my attempts, or suggest a better way of doing this. I've also played a bit with matrix, and less so with sapply, but don't really know what I'm doing with those. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any advice greatly appreciated. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">Kerstin<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br clear="both">
_____________________________________________________________________<BR>
The Joint Nature Conservation Committee (JNCC) is the statutory adviser to Government on UK and international nature conservation, on behalf of the Council for Nature Conservation and the Countryside, Cyfoeth Naturiol Cymru (Natural Resources Wales), Natural England and Scottish Natural Heritage.  Its work contributes to maintaining and enriching biological diversity, conserving geological features and sustaining natural systems.<BR>
<BR>
JNCC SUPPORT CO. Registered in England and Wales, company no. 05380206. Registered office:  Monkstone House, City Road, Peterborough, Cambridgeshire PE1 1JY<BR>
<BR>
If you have a Freedom of Information/Environmental Information request please refer to our website page<BR>
<BR>
This message has been checked for all known viruses by JNCC delivered through the MessageLabs Virus Control Centre.<BR>
</body>
</html>