[MINC-users] calculating r-squared values

Jason Lerch jason at phenogenomics.ca
Mon Jun 11 11:07:18 EDT 2012


You have to save your output to a variable:

output <- mincApply(gf1$FA, quote(fff(x)))

and then call mincWriteVolume(output, "filename.mnc")

If you didn't do that, the internal R variable .Last.value would have saved your last computation - though if you did anything else since then (and the mincWriteVolume call might apply, I'm not sure), then you'll have to rerun mincApply and assign its output to some variable.

Jason

On 2012-06-11, at 10:25 AM, Jared Rowley wrote:

> Hi Jason,
> 
> Everything appeared to work however I'm a little unclear how to save the
> data now.  (It does take a very long time to run).
> 
> Here is my code.  The last line was my attempt to save the data:
> 
> gf1 <- read.csv("dti_nvm_gd.csv")
>> fff <- function(x) { return(summary(lm(x ~ score, gf1))$r.squared) }
>> mincApply(gf1$FA, quote(fff(x)))
> Number of volumes: 91
> Volume sizes: 193 229 193
> In slice
> 0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20
> 21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39
> 40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58
> 59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77
> 78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96
> 97  98  99  100  101  102  103  104  105  106  107  108  109  110  111
> 112  113  114  115  116  117  118  119  120  121  122  123  124  125  126
> 127  128  129  130  131  132  133  134  135  136  137  138  139  140  141
> 142  143  144  145  146  147  148  149  150  151  152  153  154  155  156
> 157  158  159  160  161  162  163  164  165  166  167  168  169  170  171
> 172  173  174  175  176  177  178  179  180  181  182  183  184  185  186
> 187  188  189  190  191  192
> Done
> 
>> mincWriteVolume(fff,"rsquared_test.mnc", "score")
> Error in minc.dimensions.sizes(like.filename) :
>  Error opening input file: score.
> 
> Thanks again,
> 
> Jared
> 
> 
> On Fri, Jun 8, 2012 at 12:39 PM, Jason Lerch <jason at phenogenomics.ca> wrote:
> 
>> Try replacing FA with x - mincApply assigns the current voxel to the
>> variable x in its loop. I.e.:
>> 
>> library(RMINC)
>> gf1 <- read.csv("dti_gd.csv")
>> fff <- function(x) { return(summary(lm(x ~ score, gf1))$r.squared) }
>> mincApply(gf1$FA, quote(fff(x)))
>> 
>> Jason
>> 
>> On 2012-06-08, at 11:32 AM, Jared Rowley wrote:
>> 
>>> Hi Jason,
>>> 
>>> Thanks for the response.
>>> 
>>> I did the following and got an error do you have any suggestions:
>>> 
>>> rm(list=ls(all=TRUE))
>>>> library(RMINC)
>>>> gf1 <- read.csv("dti_gd.csv")
>>>> fff <- function(x) { return(summary(lm(FA ~ score, gf1))$r.squared) }
>>>> mincApply(gf1$FA, quote(fff(x)))
>>> Number of volumes: 91
>>> Volume sizes: 193 229 193
>>> In slice
>>> 0 Error in storage.mode(y) <- "double" :
>>> invalid to change the storage mode of a factor
>>> In addition: Warning message:
>>> In model.response(mf, "numeric") :
>>> using type="numeric" with a factor response will be ignored
>>> 
>>> FA is a column of minc files and score is a column of integers I want to
>>> correlate with FA.
>>> 
>>> Thanks very much,
>>> 
>>> Jared
>>> 
>>> 
>>> On Wed, Jun 6, 2012 at 1:35 PM, Jason Lerch <jason at phenogenomics.ca>
>> wrote:
>>> 
>>>> This should work, though is going to be slow:
>>>> 
>>>> fff <- function(x) { return(summary(lm(x ~ genotype, gf))$r.squared) }
>>>> 
>>>> mincApply(filenames, quote(fff(x)))
>>>> 
>>>> Note: replace the formula in that function with the appropriate formula
>>>> for your purposes, and filenames should be a vector of your filenames.
>>>> Could be worth specifying a mask, as this will run for a few hours.
>>>> 
>>>> And I haven't actually tested it, so it might not run at all!
>>>> 
>>>> Jason
>>>> 
>>>> On 2012-06-05, at 4:18 PM, Jared Rowley wrote:
>>>> 
>>>>> Hi Minc Users,
>>>>> 
>>>>> I was wondering if anyone knows a way calculate R-squared values on a
>>>> voxel
>>>>> level from a linear regression.
>>>>> 
>>>>> I assume there is a way with either glim_image or RMINC however reading
>>>>> though the documentation I could not find a solution.
>>>>> 
>>>>> Thanks very much,
>>>>> 
>>>>> Jared
>>>>> _______________________________________________
>>>>> MINC-users at bic.mni.mcgill.ca
>>>>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>>>> 
>>>> _______________________________________________
>>>> MINC-users at bic.mni.mcgill.ca
>>>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> Jared Rowley
>>> Translational Neuroimaging Laboratory
>>> McGill Centre for Studies in Aging
>>> Douglas Hospital Research Center
>>> McGill University
>>> 6825 LaSalle Blvd.
>>> Montreal, QC Canada
>>> H4H 1R3
>>> _______________________________________________
>>> MINC-users at bic.mni.mcgill.ca
>>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>> 
>> _______________________________________________
>> MINC-users at bic.mni.mcgill.ca
>> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users
>> 
> 
> 
> 
> -- 
> Jared Rowley
> Translational Neuroimaging Laboratory
> McGill Centre for Studies in Aging
> Douglas Hospital Research Center
> McGill University
> 6825 LaSalle Blvd.
> Montreal, QC Canada
> H4H 1R3
> _______________________________________________
> MINC-users at bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-users



More information about the MINC-users mailing list