2015年7月28日 星期二

7.28 Learning handling dataframe by sqldf in R

http://anythingbutrbitrary.blogspot.com/2012/08/manipulating-data-frames-using-sqldf.html
  • A useful blog for learning using sqldf to conduct query in R.

One more tip:
> s01 <- sqldf("select * from data where [group.code] = 'a'")
# The bracket avoids misunderstanding of dot in sqldf. The dot has another meaning
# in SQL (e.g., separating table name from column name) and is replaced by an
# underscore before sending the data to SQLite.
# URL: http://stackoverflow.com/questions/19019883/how-to-handle-column-names-not-supported-by-sqldf-in-r

2015年7月27日 星期一

7.27 R coding - Don't forget the cached input <<-

When using "<<-" instead of "<-", the variable is cached and can be used outside the function. This will be useful especially when one wants to execute a bunch of function within a single call.

2015年7月24日 星期五

7.24 Demean Categorical Variable, Seriously?

What if the categorical variables containing multiple values which are completely irrelevant?

2015年7月23日 星期四

7.23 But we need to figure out how to use GLM do to that first.

As the title indicated. This is taking forever. GLM is so slow.

And there are two websites which is ridiculous. A few complaints here just releasing the stress.
For categorical covariates (e.g. gender), treat in exactly the same way as continuous covariates - that is, use two indicator values (e.g. 0 and 1) and then demean these values before entering them into the EV. 

To adjust for multiple covariates, simply add more EVs to the model, one for each additionally covariate and mean center each covariate.

7.23 Using gedit to create specific design.con and design.mat

This link from UTexas is very helpful:
http://wikis.la.utexas.edu/imagelab/book/statistical-analysis-fa-values

  • The design.mat files looks like this:
/NumWaves 2
/NumPoints 4
/PPheights 1 1
/Matrix
0 1
1 0
1 0
0 1
  • The design.con file will look like this:
/NumWaves 2
/NumContrasts 2
/PPheights 1 1
/Matrix
1 -1
-1 1

Just open gedit on ssh shell and modify these parameters when later on need to add covariate into the statistical analysis.

Another way is using R to do that, which requires additional step (import the data, re-combine the rows with attention paying to the datatype, then export it (which I still not figure out)). Anyway, gedit is super fast.
 

2015年7月21日 星期二

7.21 Add pagebreak in Rmd for LaTeX conversion

Very technical detail but useful to learn. Thanks for the midterm from CMU.

http://www.stat.cmu.edu/~nmv/setup/stat202/tests/midterm-student-version.Rmd

Simply adding a line "\pagebreak" will introduce a page break for later on converting to a LaTeX pdf file. Remember to leave a line with the latter contents.

And just figured out that I can make system call in R (system()). This is so cool, lazy boy.

7.21 VA Research - Add Covariate in TBSS

In the coming future, it is very likely that I will be referencing this website for performing statistics on my master thesis, so I am going to mark it down here.

http://white.stanford.edu/newlm/index.php/MrVista_TBSS

2015年7月20日 星期一

7.20 VA Self Study - Coursera and MRI

Today I watched the first video lectures of the third week for Statistical Inference class, which is about Statistical Power. Better to visualize the concept by two side-by-side Gaussian distributions.

(Nishimura p.51) T2 relaxation: The pertinent frequency components of the fluctuating z fields are those near zero. These components contribute only to the T2 relaxation process and not to T1. Therefore T2 is largely independent of field strength.
In solids, the presence of relatively slow fluctuations creates a large resonant frequency broadening effect and thus extremely rapid T2 decay. In biological tissue, spins bound to lumbering macromolecules also experience rapid T2 decay while relatively mobile spins (e.g. those in water) exhibit much slower decay. However, because of rapid exchange of protons between these two types of environments, the effective T2 is some average of the two relaxation rates.

2015年7月19日 星期日

7.19 Coursera Statistical Inference - Frustration from Compiling

Compiling. Compiling. Compiling again! Every time the little imperfection from converting one file to another using the automatic codes just make me annoyed and frustrated. But I learned something.

  • Reduce figure sizes and fit it between bullets instead of popping up at random spots. This proves to be very hard for several reasons:
    • Rmd file is built primarily for HTML file conversion and is best at adjusting figure size for HTML file specifically. Things get messy when it comes to LaTeX pdf.
    • In Rmd file, adjusting the size for .png file is at best when using the fig.width and fig.length parameters. LaTeX prefers pdf figures.
    • Letting Rmd file do plotting by inserting codes is probably worse than inserting figures from other places.

7.19 Coursera Statistical Inference Project 1

Everyday I learnt something new. Mission Hall study on Sunday is a funny adventure.

Get familiar with Rmd and pandoc convertion to LaTeX file is like picking up new languages.

Adding a -V flag after pandoc can specify the margin size of the pdf you want. Greatly reduced the report pages. Next is thinking about how to reduce the freaking figure size. They looked so horrible.


2015年7月17日 星期五

7.17 Successfully launched TBSS processing

Today I did my first TBSS trial with success. It was a thrill. Professor and Dr.Murray are also very excited that this is a significant progress.

Once gathering sufficient amount of data, I can start getting results right away. So now let's just be patient and wait for the fixing of those terrible network and database!

TBSS, master thesis, you can do it Kai!

2015年7月16日 星期四

7.16 How do T1 and T2 values vary as a function of field strength?

http://www.mri-q.com/bo-effect-on-t1--t2.html

Quick fact: for typical range of field strengths used for clinical MRI (0.3T - 3.0 T), T1 approximatly doubles, and T2 is relatively unchanged.

Some mechanisms of T2 relaxation (such as chemical exchange and molecular diffusion) may actually be more efficient at higher fields and therefore cause a reduction in T2 values.

7.16 VA Reading - NARR_Module3E_CTSI_Diffusion_Imaging_2014

In DWI, 3 gradient directions allow identifying CNS abnormalities such as cerebral ischemia, TBI, tumors
With more gradient directions, identifying white matter pathology including axonal injury and/or myelin damage will be optimized
Tensor model cannot resolve fiber orientation across intersecting axes (crossing fibers) within the same voxel; high angular resolution diffusion imaging (HARDI) allows more complex models of diffusion and resolve this issue
Non-tensor models of diffusion:
  • Diffusion spectrum (DSI): full distribution of orientation and magnitude
  • Orientation distribution function (Q-ball): no magnitude info, only orientation
  • Ball-and-stick: orientation and magnitude for up to N anisotropic compartments
  • Tensor (DTI): single orientation and magnitude
This diagram is a nice demonstration (Catani and Thiebaut de Schotten, 2008):