• Arbitrary text for in-text citation in Mendeley

    It's taken an embarrassingly long time to figure out how to quickly add arbitrary text to an in-text citation with Mendeley's Word plug-in. Until this week, most (all?) of my submitted manuscripts have had sections that looked like this: That annoying )( doesn't look great, but it was even more annoying to try and type inside the left parenthesis, the deal with the pop-up from Mendeley asking if I wanted to keep the manual edit every single time I re-opened the word document. To add arbitrary text, click on the citation, then click on the "Edit Citation" button in the Mendeley toolbar. This brings up the citation editor. Click on…

  • Formatted summary tables R

    One of the slightly annoying issues I've had with using the summary() function in R are the multiple steps it takes to get the parameters from a fitted model into a format that's useful for pasting into a manuscript. After a lot of trial and error, the workflow I settled on used Daniel Lüdecke's sjstats and sjPlot packages. sjPlot has the very helpful plot_model() function and tab_model() functions, that make it very easy to plot marginal effects and interactions, or render HTML tables that can be cut and pasted. However, sjstats also used to contained std_beta(), a function would could be passed a fitted model object (e.g. from lmer() )…

  • Adjusting for lag

    One thing I hate is heisenbugs. One recent one is that some of the triggers being sent by E-prime to our EEG systems have been incorrect. For instance, the first four triggers should be 1, 5, 6, 2. But in two of the last five participants, they've been 1, 5, 7, 3. There are no methods that I know of that would lead E-prime to send anything other that the trigger codes that I provide it. No changes were made to the E-prime program, and I confirmed that the timing files generated by E-prime show that the correct codes should have been sent. I dug in a little more, and…

  • Using 3dClustSim with SPM

    I've been working on an fMRI dataset with 80+ subjects. For second-level thresholding, I've started using AFNI's 3dClustSim to estimate the appropriate cluster extent threshold given a particular height threshold (e.g. p < .005). The best (i.e. least likely to inflate Type I errors) method requires specific smoothness estimates from the first-level analysis. The basic workflow is: Write residuals from model estimation Estimate smoothness from the residuals Average smoothness estimates across participants Use average estimates to condition 3dClustSim when determining thresholds Step 1. Write residuals The first step is the have SPM write out the residuals images during model estimation. There are two relatively straightforward was to accomplish this: If…

  • Visualizing signal dropout across subjects

    One of my current projects involves working with some data that I did not collect. I have the smoothed and normalized NIfTI images and the first-level stats images, including SPM.mat and the con_*, beta_*, and spmT_* files. Generating the second-level images is straight-forward, but when I visualized simple effects, there was larger than expected signal dropout in vmPFC and temporal pole around the sinuses. It seemed plausible that across the 80+ subjects in the dataset, there might be a handful of subjects with abnormally high dropout. Losing one or two individual subjects seems like a reasonable price to pay to recover vmPFC signal, since the task involves social decision-making. Rather…

  • enumerate()

    I was hoping to regularly update, but revisions and data collection have gotten in the way (not a bad problem to have). This is just a short shout-out to the wonderful enumerate() function in Python3. It adds indexing to iteration. So, instead of: You can do: Granted, that's a pretty simple case, and you don't gain much. However, I've been working on rescoring/relabeling trigger codes in EEG timing files. The files are ~500 lines of text. Each event has an index, timestamp, description, type, and duration. Those five values are separated by commas, so my solution was to create a list of lists (the header lines in the timing file…

  • Python Image2PDF

    While running participants, we use multi-page logs (e.g. arrival time, researchers present, start time of each run of each task). After a session is over, we scan these to save on the server for easy reference later. However, with the most recent round of computer upgrades, the scanner functionality has decreased. Specifically, saving multiple images to a single PDF no longer works. Opening multiple image files is a pain, so I wanted to find a quick way to convert the combine the images into a PDF. My solution was to use the img2pdf package and some Python3 code. The script I came up with does 4 things: Read in all…

  • Utilities: Python and xjView reports

    I use xjView to visualize statistical maps most of the time. One reason why, is that it's report function generates a lot of useful information, including not only the peak MNI coordinates and peak intensity, but also a breakdown of the number of voxels within each cluster than within specific AAL labels (is that parahippocampal or amgydala?). I also use these reports when I need to generate tables for manuscripts. The processes isn't overly elegant, but it's functional: Load the stats image. Generate the xjView report. Paste the report from the MATLAB command window into a *.txt document. Convert the *.txt document into a comma-separated table. Open the CSV tables…