tag:blogger.com,1999:blog-6710487119650146215.post1051531260605077794..comments2018-02-16T02:45:47.656-07:00Comments on R Tutorial Series: R Tutorial Series: Zero-Order CorrelationsJohnhttp://www.blogger.com/profile/05331039307550313006noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-6710487119650146215.post-39045493577955615262011-08-23T09:30:54.851-07:002011-08-23T09:30:54.851-07:00Hi Phoebe,
Check out the Scatterplots tutorial. T...Hi Phoebe,<br /><br />Check out the Scatterplots tutorial. There is an explanation by a commenter on how to plot markers by group.<br /><br />JohnJohn M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-34897242832300852102011-08-23T09:20:01.580-07:002011-08-23T09:20:01.580-07:00Hi there,
I want to assign different shapes to 4 ...Hi there,<br /><br />I want to assign different shapes to 4 groups of data that I&#39;m plotting together. I know how to put in the shapes but not how to assign them to a specific group (e.g.; C2=square, C3=circle, etc). Thanks so much for your help.<br /><br />PhoebeAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-23146057925638759632011-06-03T16:29:42.476-07:002011-06-03T16:29:42.476-07:00You have to create a variable containing the data....You have to create a variable containing the data. Datavar is a placeholder name for my example, although you could use any name you wish. <br /><br />For all tutorials, also be sure to read through the entire tutorial and complete all steps without jumping ahead in the code.John M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-54413399993689555332011-05-30T05:36:52.699-07:002011-05-30T05:36:52.699-07:00Hi, i am getting an error message datavar not foun...Hi, i am getting an error message datavar not found? do i need to attach a libarary?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-46468560152842756022011-01-04T21:12:00.347-07:002011-01-04T21:12:00.347-07:00P.S. I was also notified that the rcorr function i...P.S. I was also notified that the rcorr function in the Hmisc package may be useful for what you are doing, since it accepts a matrix X and returns a correlation matrix with p-values. I haven&#39;t used the function myself.<br /><br />JohnJohn M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-5809056600437814422011-01-04T20:59:33.609-07:002011-01-04T20:59:33.609-07:00Hi Elspeth,
I have never done what you describe, ...Hi Elspeth,<br /><br />I have never done what you describe, but I see that a similar question was posted almost ten years ago on the R Help listserv: https://stat.ethz.ch/pipermail/r-help/2001-November/016201.html<br /><br />You may want to search around for an answer in the archives/Google or consider pursuing it further on the listserv. This seems like a question that would be valuable for the community to answer.<br /><br />For a makeshift solution, perhaps you could use a For loop to run each x and y variable combination through the cor.test() function?<br /><br />JohnJohn M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-34481102987509832102011-01-04T15:42:42.235-07:002011-01-04T15:42:42.235-07:00Hi John,
I have a lot of correlations to run, but ...Hi John,<br />I have a lot of correlations to run, but I need significance values. How do I get a table with the r-values for the correlations between my variables but also p-values? (The cor.test() function doesn&#39;t work for multiple variables like cor() does).<br /><br />Thanks,<br />ElspethAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-85293911083367265832010-11-27T08:21:18.512-07:002010-11-27T08:21:18.512-07:00I have updated the data file to use 0, 1, and 2, r...I have updated the data file to use 0, 1, and 2, rather than Basal, DRTA, and Strat. Hopefully, this will help those of you experiencing the x must be numeric error.John M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-22546201511119008152010-11-27T07:56:56.748-07:002010-11-27T07:56:56.748-07:00Hi,
I recommend reading the above posts, as other...Hi,<br /><br />I recommend reading the above posts, as others have also experienced this problem. Ruben reported it as happening on a particular version of R for OSX, while Luca offered a modified CSV file which replaced the text terms with numeric ones.<br /><br />JohnJohn M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-25968530133081229792010-11-24T20:13:31.225-07:002010-11-24T20:13:31.225-07:00I am new to R and faithfully following this tutori...I am new to R and faithfully following this tutorial. I copied into R one by one the commands from &quot;correlational analysis example (.txt)&quot;. Unfortunately, for the command<br /><br />&gt; cor(datavar)<br /><br />I get the message<br /><br />Error en cor(datavar) : &#39;x&#39; must be numeric<br /><br />Any suggestions?<br /><br />ThanxAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-50136711290284496172010-11-18T21:26:36.371-07:002010-11-18T21:26:36.371-07:00Hi John,
Attempting this specific tutorial on R 2...Hi John,<br /><br />Attempting this specific tutorial on R 2.12.0 running on a Windows box, and I get the same error as Ruben above:<br /><br />&gt; dataset &lt;- read.csv(&quot;dataset_readingTests.csv&quot;)<br />&gt; cor(dataset)<br />Error in cor(dataset) : &#39;x&#39; must be numeric<br />&gt; numericGroup &lt;- as.numeric(dataset$Group)<br />&gt; ls()<br />[1] &quot;dataset&quot; &quot;numericGroup&quot;<br />&gt; cor(dataset,numericGroup)<br />Error in cor(dataset, numericGroup) : &#39;x&#39; must be numeric<br /><br />I supposed it would work if I substituted out the Group ASCII for a numeric, but I see the advantage in getting the results you initially achieved. Have there been any clues as to why this is the case, or being above to force define Group to being numeric somehow?<br /><br />Thanks,<br /><br />JonJonhttp://jonlin.canoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-25981208106224651372010-07-28T21:30:08.801-07:002010-07-28T21:30:08.801-07:00Hi Luca,
Thanks for your contribution.
JohnHi Luca,<br /><br />Thanks for your contribution.<br /><br />JohnJohn M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-20927367129788129082010-07-28T05:55:44.424-07:002010-07-28T05:55:44.424-07:00Hello
I had the same problem as Ruben above but I ...Hello<br />I had the same problem as Ruben above but I solved it by uploading this file:<br />as you can see I replaced:<br /> Basal with 0<br /> DRTA with 1<br />and Strat with 2<br />it did not like to have text there<br />if you upload the csv below it will work<br />-----<br />Subject,Group,PRE1,PRE2,POST1,POST2,POST3<br />1,0,4,3,5,4,41<br />2,0,6,5,9,5,41<br />3,0,9,4,5,3,43<br />4,0,12,6,8,5,46<br />5,0,16,5,10,9,46<br />6,0,15,13,9,8,45<br />7,0,14,8,12,5,45<br />8,0,12,7,5,5,32<br />9,0,12,3,8,7,33<br />10,0,8,8,7,7,39<br />11,0,13,7,12,4,42<br />12,0,9,2,4,4,45<br />13,0,12,5,4,6,39<br />14,0,12,2,8,8,44<br />15,0,12,2,6,4,36<br />16,0,10,10,9,10,49<br />17,0,8,5,3,3,40<br />18,0,12,5,5,5,35<br />19,0,11,3,4,5,36<br />20,0,8,4,2,3,40<br />21,0,7,3,5,4,54<br />22,0,9,6,7,8,32<br />23,1,7,2,7,6,31<br />24,1,7,6,5,6,40<br />25,1,12,4,13,3,48<br />26,1,10,1,5,7,30<br />27,1,16,8,14,7,42<br />28,1,15,7,14,6,48<br />29,1,9,6,10,9,49<br />30,1,8,7,13,5,53<br />31,1,13,7,12,7,48<br />32,1,12,8,11,6,43<br />33,1,7,6,8,5,55<br />34,1,6,2,7,0,55<br />35,1,8,4,10,6,57<br />36,1,9,6,8,6,53<br />37,1,9,4,8,7,37<br />38,1,8,4,10,11,50<br />39,1,9,5,12,6,54<br />40,1,13,6,10,6,41<br />41,1,10,2,11,6,49<br />42,1,8,6,7,8,47<br />43,1,8,5,8,8,49<br />44,1,10,6,12,6,49<br />45,2,11,7,11,12,53<br />46,2,7,6,4,8,47<br />47,2,4,6,4,10,41<br />48,2,7,2,4,4,49<br />49,2,7,6,3,9,43<br />50,2,6,5,8,5,45<br />51,2,11,5,12,8,50<br />52,2,14,6,14,12,48<br />53,2,13,6,12,11,49<br />54,2,9,5,7,11,42<br />55,2,12,3,5,10,38<br />56,2,13,9,9,9,42<br />57,2,4,6,1,10,34<br />58,2,13,8,13,1,48<br />59,2,6,4,7,9,51<br />60,2,12,3,5,13,33<br />61,2,6,6,7,9,44<br />62,2,11,4,11,7,48<br />63,2,14,4,15,7,49<br />64,2,8,2,9,5,33<br />65,2,5,3,6,8,45<br />66,2,8,3,4,6,42<br />------<br /><br />LucaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-75474697592285344292010-06-19T08:53:09.170-07:002010-06-19T08:53:09.170-07:00Hi Kurt,
You can select just the rows that you wa...Hi Kurt,<br /><br />You can select just the rows that you want to use from your dataset and save them into a new variable. Then you can perform your operations on that dataset. Here is an example.<br /><br />&gt; #read data into R<br />&gt; dataset &lt;- read.csv(&quot;xyData.csv&quot;)<br />&gt; dataset<br /> x y<br />1 1 5<br />2 4 2<br />3 6 3<br />4 7 4<br />5 8 4<br />6 3 8<br />7 2 3<br />8 9 5<br />9 1 9<br />10 2 10<br />11 3 3<br />12 3 4<br />&gt; #create a second dataset that excludes the first row<br />&gt; subset &lt;- dataset[2:12,]<br />&gt; subset<br /> x y<br />2 4 2<br />3 6 3<br />4 7 4<br />5 8 4<br />6 3 8<br />7 2 3<br />8 9 5<br />9 1 9<br />10 2 10<br />11 3 3<br />12 3 4<br />&gt; #calculate a correlation on the new subset<br />&gt; cor(subset)<br /> x y<br />x 1.0000000 -0.3958011<br />y -0.3958011 1.0000000John M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-87117291795170500252010-06-19T05:25:26.798-07:002010-06-19T05:25:26.798-07:00Hi, I have a question about correlation in R.
I a...Hi, I have a question about correlation in R. <br />I am trying to compare time varying correlations between an asset and the S&amp;P 500. I want to find the correlation for each date that I have data for. <br />Here for example. say X = 1,4,6,7,8,3,2,9,1,2,3,3 and Y =5,2,3,4, 4,8,3,5,9,10,3 ,4 how can I find the correlation between X and Y for every point starting with when X = 4 and Y =2.<br /><br />Thanks for the help!<br />KurtAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-71531838612838775712010-05-07T21:41:54.032-07:002010-05-07T21:41:54.032-07:00Hi John,
I think I found the problem.
The error m...Hi John, <br />I think I found the problem.<br />The error message only appears with R version 2.11.0 for OS X. <br />I tried to execute the code with R 2.10.1 for OS X and it worked perfectly.<br />I&#39;m going to report the issue in the R user groups.<br />Regards,<br />RubenRubennoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-37723765339483871252010-05-05T07:58:19.570-07:002010-05-05T07:58:19.570-07:00Thanks, Ruben.
Please come back and share the sol...Thanks, Ruben.<br /><br />Please come back and share the solution once you find it.John M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-89916747377878240672010-05-05T02:48:41.720-07:002010-05-05T02:48:41.720-07:00Hi John,
I tried your suggestion but unfortunately...Hi John,<br />I tried your suggestion but unfortunately I got the same error message.<br />I&#39;m really at a loss as to what is causing the problem so I will try to ask the R community.<br />Anyway, thanks a lot for your help and for creating such great tutorials.<br />Regards,<br />RubenRubennoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-9322915664554193582010-05-02T11:09:37.081-07:002010-05-02T11:09:37.081-07:00Hi Ruben,
Another reader commented that attach() ...Hi Ruben,<br /><br />Another reader commented that attach() can cause unexpected console errors, although I have never experienced problems with it up to this point. So, one other thing to try might be typing out the entire column name without using attach(). You could do this:<br /><br />&gt; #read in the data<br />&gt; datavar &lt;- read.csv(&quot;dataset_readingTests.csv&quot;)<br />&gt; #create a variable containing the numeric version of the Group column<br />&gt; numericGroup &lt;- as.numeric(datavar$Group)<br />&gt; #correlate the numeric Group variable with the original dataset<br />&gt; cor(datavar, numericGroup)<br /><br />Otherwise, I&#39;m not sure what to do at this point. I have never encountered the error message that you have posted. For the record, I am using Mac OS X 10.6.3 and R 2.10.0 GUI 1.30 Leopard build 64-bit (5511).John M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-12891690815845000042010-05-01T21:52:05.447-07:002010-05-01T21:52:05.447-07:00Hi John,
I executed the same commands using the R ...Hi John,<br />I executed the same commands using the R 2.10.1 for Windows in my virtual machine and everything worked as expected.<br />Now that I know it&#39;s related to OS X, do you have any ideas how to solve it?<br />Many thanks in advance,<br />RubenRubennoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-70406014396661016942010-05-01T21:31:23.644-07:002010-05-01T21:31:23.644-07:00Hi John,
thanks for the suggestion.Unfortunately I...Hi John,<br />thanks for the suggestion.Unfortunately I&#39;m still having the same problem (I&#39;m using a MacBook Pro with OS X 10.5.8 and R 2.11.0)<br />This is what I tried:<br /><br />&gt; datavar&lt;-read.csv(&quot;dataset_readingTests.csv&quot;)<br />&gt; numericGroup&lt;-as.numeric(Group)<br />Error: object &#39;Group&#39; not found<br />&gt; attach(datavar)<br />&gt; numericGroup&lt;-as.numeric(Group)<br />&gt; cor(datavar,numericGroup)<br />Error in cor(datavar, numericGroup) : &#39;x&#39; must be numeric<br />&gt; cor(numericGroup,datavar)<br />Error in cor(numericGroup, datavar) : &#39;y&#39; must be numeric<br /><br />May it be a problem with the actual file? My hardware/software combination?<br /><br />Thanks in advance for any suggestions.<br />Regards,<br />RubenRubennoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-74426153673539500242010-05-01T20:06:34.618-07:002010-05-01T20:06:34.618-07:00Hi Ruben,
I see what is happening now. You have c...Hi Ruben,<br /><br />I see what is happening now. You have created a variable named &quot;Group&quot; that contains the numeric version of the Group column from the dataset. However, this does not modify the original Group column in the dataset. So, when you try to run cor() on the datavar, it still sees the original text values for the Group column and cannot form a correlation. Instead, use your new Group variable and the original dataset inside the cor() function. Here is an example:<br /><br />&gt; #read in the data<br />&gt; datavar &lt;- read.csv(&quot;dataset_readingTests.csv&quot;)<br />&gt; #create a variable containing the numeric version of the Group column<br />&gt; numericGroup &lt;- as.numeric(Group)<br />&gt; #correlate the numeric Group variable with the original dataset<br />&gt; cor(datavar, numericGroup)<br /> [,1]<br />Subject 0.94291728<br />Group NA<br />PRE1 -0.18571906<br />PRE2 -0.05915376<br />POST1 0.13223726<br />POST2 0.43986753<br />POST3 0.19983331<br />Warning message:<br />In cor(datavar, numericGroup) : NAs introduced by coercion<br /><br />This will get you a correlation between Group (numeric) and all of the other columns in the dataset. Of course, you will get an NA still on the Group-Group correlation since the original dataset still contains text values.John M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-45547599536358645572010-05-01T19:43:52.791-07:002010-05-01T19:43:52.791-07:00Hi John,
thanks for the suggestion but unfortunate...Hi John,<br />thanks for the suggestion but unfortunately it didn&#39;t work for me.<br />I tried the following:<br /><br />&gt; datavar &lt;- read.csv(&quot;dataset_readingTests.csv&quot;)<br />&gt; attach(datavar)<br />&gt; Group&lt;-as.numeric(Group)<br />&gt; cor(datavar)<br />Error in cor(datavar) : &#39;x&#39; must be numeric<br /><br />The funny thing is that when I checked all the fields with the is.numeric () function, the answers were all true and I could actually calculate correlations pairwise.<br />Any other suggestions would be greatly appreciated.<br />Regards,<br />RubenRubennoreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-87137069271542912572010-05-01T08:29:48.939-07:002010-05-01T08:29:48.939-07:00Hi,
It sounds like your &#39;x&#39; variable is n...Hi,<br /><br />It sounds like your &#39;x&#39; variable is not numeric and therefore R is unable to correlate it. Try making your &#39;x&#39; data numeric following the dummy coding technique demonstrated here: http://rtutorialseries.blogspot.com/2010/02/r-tutorial-series-regression-with.htmlJohn M. Quickhttps://www.blogger.com/profile/05331039307550313006noreply@blogger.comtag:blogger.com,1999:blog-6710487119650146215.post-86194839296207454402010-05-01T03:30:21.159-07:002010-05-01T03:30:21.159-07:00Dear John,
I was trying to replicate your example ...Dear John,<br />I was trying to replicate your example using cor()for calculating all the correlations with R 2.11.0 but I got the following error message:<br /><br />&gt; cor(datavar)<br />Error in cor(datavar) : &#39;x&#39; must be numeric<br /><br />Any suggestions how to fix it?<br />Many thanks in advance,<br />RubenRubennoreply@blogger.com