R (Linux) – basic installation

To install the R programming environment on Linux is pretty straightforward, but it does require a little bit of know how in order to find the correct packages. As is typically the case with Linux, there are multiple ways to get things done. I like to use Synaptic for installing and removing software, but you can also use the software manager that comes with your Linux distribution (in Linux Mint it’s called Software Manager) or the command line (in KDE based distributions, Konsole).

For the most up-to-date installation of R, it’s actually best to install directly from the R repository. A list of Linux repositories for the R environment is located here. In order to install from the repository, you need to update your list of repositories in Synaptic. To access your repository list in Synaptic, click on Settings -> Repositories.

In the new Software Sources window, click on “Additional repositories” and you’ll get this window:

Click on Add a new repository. You’ll get this window:

The exact information you put into that window will vary based on which mirror you chose. Here is what I added in mine:

deb xenial/

In order to ensure you have the right files and to follow best security practices, you should install the signing key as well. Directions for installing the signing key are found here, but it can be done with a simple command from a terminal:

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys E084DAB9

Once you have done all of that, you can install R from Synaptic.

First, open Synaptic, which will require your password. You’ll get the basic Synaptic Package Manager window:

Next, in the search box, search for “r-base”. Right-click it and select “Mark for installation” to install “r-base”:

In the above screenshot, I have already installed r-base, so the option “Mark for installation” is greyed out. But, obviously, that’s what I already did. When you select this, Synaptic will automatically select all the other necessary packages (there are about 10 to 15 additional packages necessary for R to run: r-cran-class, r-cran-lattice, r-cran-spatial, r-cran-survival, r-cran-codetools, r-cran-nnet, r-cran-mass, r-cran-boot, r-cran-nlme, r-cran-rpart, r-cran-cluster, r-cran-kernsmooth, r-cran-foreign, r-cran-mgcv, r-cran-matrix, r-recommended, r-base-core).

If you plan on installing any other R packages, it’s not a bad idea to also install “r-base-dev,” as it helps fill in dependencies for other packages.

Once you’ve selected r-base, hit Apply in Synaptic and all the software will be installed.

You now have the base software for R installed.

To open the R environment in a terminal, launch a terminal and simply type “R” at the prompt, like this:

Here’s where things can get a little complicated. To do different things in R requires various libraries or packages. Some of these can be installed using the R terminal while others need to be installed from your Linux distribution’s repositories. To install a library or package using the R terminal, you use the following command once you have opened the R environment:

install.packages(“PACKAGENAME”)

The first time you run this, the R environment will ask you to select a mirror.

Choose one close to your location. R will then install the package, assuming you type everything correctly.

NOTES:

Before you start trying to install additional R packages, it’s a very good idea to install the following Linux packages:

r-base-dev build-essential

If you run into an error message, there are several possibilities. First, check to make sure you typed everything correctly. R is not forgiving on spelling mistakes. Second, if the error is something like:

installation of package ‘PACKAGENAME’ had non-zero exit status

Or

dependency ‘PACKAGENAME’ is not available

There is a good chance that you need to install a package or library using Synaptic (or from a terminal using apt). For instance, to install the “tm” package, there is an unsatisfied dependency (meaning, a library or package that needs to be installed but cannot be installed using the R installer). The dependency is the ‘slam’ package. This can be installed using Synaptic (or, from a terminal, using the command “sudo apt-get install r-cran-slam”). Once you’ve installed the dependency, try re-installing the package and the error messages should go away.

 

NOTES:

I also have found that I like RStudio as an IDE for working with R. It’s a little bit friendlier to use than a straight command line interface as it keeps track of variables and loaded libraries. The personal version for your desktop can be downloaded here.

And a note on RStudio on Linux. I regularly get an offset from the cursor location and where the cursor actually is in the command window. It turns out this is a font issue. If you go up to Tools -> Global Options -> Appearance and change the font to anything else, this problem will go away.

 389 total views

Limesurvey: How to Randomly Assign Participants to Different Conditions (i.e., Experimental Designs)

I’ve used LimeSurvey for a long time and really like the software.  It’s powerful, yet very easy to use.  But one thing I couldn’t figure out with the software was how to assign participants to one of several conditions within a single survey.  For example, if you want to randomly assign participants in your survey to one of three groups and one of those groups will see some intervention, another group will see a different intervention, and the third group will see a control condition, as in an experimental design, I couldn’t figure out how to do that before.  Turns out, it is possible.  I found this tutorial that explained it, but it wasn’t all that clear, so I’m creating a tutorial here to make it very clear how this works.

What I wanted to do is like the hypothetical scenario I described above.  I am conducting a survey and have two experimental conditions; participants are going to read one of two vignettes that are designed to influence them in specific ways and one control condition in which the vignette is designed not to influence participants in any way.  I want to randomly assign every person who takes the survey to one of these three conditions so they only see one of the three vignettes.  Here’s how you do this.

First, you have to create a variable in LimeSurvey that randomly assigns each participant to one of the groups.  This should basically be the first variable in your survey.  But, the key is that you don’t let participants see the variable.  So, you add a new question to your first Question group:

limesurvey1

You can name that variable whatever you want (this goes in the Code: box), but I named mine “random.”

limesurvey2

Then, you need to choose the type of question.  Go down to where it says “Question type:” and select “Equation”:

limesurvey3

The equation itself goes in the “Question:” box, like this:

limesurvey4

The equation you use is the following:

{rand(1,3)}

What this equation tells LimeSurvey to do is to select a random number between 1 and 3 (the two values in the parentheses) and assign that to this particular participant (if you have more conditions, you can increase the number of groups by increasing the second integer – i.e., change 3 to 4, 5, 6, etc.).

You have to do one more thing before you’re done creating the question.  Go down to “Show advanced settings” and click on it.  It will open the advanced settings options.  Scroll down to where it says, “Always hide this question” and select “Yes” from the drop down menu.  This tells LimeSurvey that you don’t want participants to see this question. Once you’ve done that, click on “Save” and you’ve now created the variable that randomly assigns participants to one of the three conditions.

limesurvey5

You’ve finished the hard part.  Now you have to tell LimeSurvey which variables go with which randomly assigned numbers and their corresponding conditions.  You do this while creating the questions.  So, start creating the questions you want the participants in each of the groups or conditions to see (these should obviously be in a later question group than the above question, or the branching won’t work).  While creating the question, scroll down to where it says, “Relevance equation”.  In that box is where you’re going to add the necessary code to assign each question to a randomly assigned condition.  The code you’ll use is the following:

  • for those assigned to condition 1, add to that box: ((random==1))
  • for those assigned to condition 2, add to that box: ((random==2))
  • for those assigned to condition 3, add to that box: ((random==3))

It should look like this:

limesurvey7

Once you’ve added the Relevance equations and hit “Save”, now you can test the survey.  You should be randomly assigned to a different condition each time and see only the questions that meet the relevance equation criteria – meaning, if you were randomly assigned to condition 1, you’ll only see the questions assigned to that condition, ditto with condition 2 and condition 3.

And there you have it – you have created a survey that includes random assignment to different conditions.

 1,464 total views

Linux: Using GIMP to wrap text in an image

I’m not an expert in graphic design, but I like playing around with images on occasion.  I had an itching to modify a logo recently that included text wrapped in a circle.  It took me a couple of hours to figure out how to wrap text like that in GIMP and the tutorials I found online were not all that clear.  So, I’m creating my own to help me remember in the future.

  1. First, install GIMP.  That kind of goes without saying, but, yeah, do that.  Then, open GIMP.
  2. Once you’ve got GIMP up and running, go ahead and open the image you want to work with or create a new image.  The size doesn’t really matter for the tutorial, so make it whatever size you need.
    gimp1
  3. You’re going to need to make sure you have the “Layers – Brushes” window open, which includes a tab for “paths” (which is the key to wrapping text).  If this is not open, you can open it under “Windows -> Layers – Brushes”:
    gimp2
  4. Now, to give us a circle to wrap the text around, click on the “Ellipse Select Tool”.
    gimp3
  5. Go ahead and draw a circle on your canvas.
    gimp5
  6. Once you have a circle, fill it with a color by going to “Edit -> Fill with FG color” (you can also fill it with the BG color; you choose these colors in the Toolbox by clicking on the colors):
    gimp6
  7. Once you’ve filled the circle, deselect it so nothing is selected by clicking anywhere outside the circle with your “Ellipse Select Tool” (or the “Rectangle Select Tool”).  We filled the circle just so we have an arc to wrap the text around.  Now comes the tricky part.  Choose your “Paths tool” in the Toolbox:
    gimp26
  8. You can create all sorts of paths with this tool – wavy lines, curved lines, jagged lines, etc.  We’re going to use it to create a curve around our circle.  To begin the curve, click on one side of the circle with the Paths Tool:
    gimp7
  9. Then click with the Paths Tool on the other side of the circle and you’ll see that it draws a line between the two points:
    gimp27
  10. How precise you are with these points is up to you.  The next step, however, is to turn our line into an arc.  To do this, move toward the middle of the line between the two points, select the line, and begin dragging it.  You’ll notice that two additional lines will be added to the end points, which help you adjust the angles of your arc. Drag the line between the two points and/or the two lines that intersect with the two points until you are satisfied with your arc:
    gimp8
  11. Now, in your “Layers – Brushes” window, look for the “paths dialog” tab:
    gimp9
  12. Click on it and you’ll see a list of all of the paths that you have created.  You can rename the path you just created by double-clicking on the name, but you don’t have to.  I renamed mine “Top Arc”:
    gimp10
  13. Now, click back to the layers dialog in the “Layers – Brushes” window:
    gimp11
  14. You’re now going to create your text.  Choose the “Text Tool” in your Toolbox:
    gimp12
  15. Draw a textbox on your canvas and type some text:
    gimp13
  16. There are some important things to address at this point.  The color of your text doesn’t matter, but the size does.  You’ll want to make sure your text is large enough so that, when you try to wrap it around your arc, it covers the full distance around the arc.  I’ll come back to how to test this in a minute, but go ahead and fiddle with this for a few minutes until you get the text size to where you think it should be.  You can always adjust it later.  You’ll also want to make sure you’ve got the right font.
    gimp14
  17. Once you’ve got your text ready, highlight your text in the text box and then right-click it.  You’ll see an option that says “Text along Path”.  That’s what you want to select as it is going to wrap your text to the path you just created. There’s a hint in the information that pops up when you hover over that option – the text will be wrapped around the currently active path.  Since we only have one path, that doesn’t matter.  But, like with layers, you can create multiple paths and simply select the active one you want to use in the “path dialog” window:
    gimp25
  18. Once you click that option, you should see your text wrap around your circle, like this:
    gimp28
  19. Hopefully it looks how you want it to.  If not, there are a couple of options.  First, if the text doesn’t make it all the way around (like mine, but I don’t care for this tutorial), increase the font size.  If the text goes too far, decrease the font size.  If the text looks misaligned, then you’ll have to go back up to the paths dialog tab in the “Layers – Brushes” window, delete the path you created earlier, and try again (start at Step 9 above).  You can fiddle with the arc or path as long as you want until you’re satisfied.  So, make sure the text looks good before going on to the next step.
  20. Once you’re happy with your wrapped text, the next step is to turn that text into a layer.  Just so you understand how GIMP thinks about paths, they aren’t layers.  They are really separate.  They don’t function like layers.  You can show them or not show them, but they won’t show up in your final image.  They are completely separate from layers.  When you wrapped that text to the path you created, you actually created a new path.  You didn’t bend your text.  To verify this, click on the “paths dialog” tab in the “Layers – Brushes” window and you’ll see a new path.  You can rename this as well.  I renamed mine to, “Top Arc Text”.
    gimp16
  21. What we want to do with our text arc is turn it into a layer we can display in our final image.  This is the tricky part.  First, create a new transparent layer by going to “Layer -> New Layer”:
    gimp17
  22. You can call this your “Arc Text” layer.  Choose “transparency” as the “Layer Fill Type”:
    gimp18
  23.  Now, just to make things a little easier, go ahead and click on the eye next to the text layer in the “layers dialog” window, so the text box goes away.
    gimp19
  24. You can also click on the eye next to the background layer, so all you can see is the newly created path on a transparent background layer.  Remember, you can’t think about the paths as layers.  You can make paths visible or not, but they are separate from layers.
    gimp20
  25. Next, select your newly created transparent layer in the “Layer dialog” window, then click on the “path dialog” tab and select your newly created path made out of the text.  You’re going to right-click on the newly created path and look for the “Path to Selection” option:
    gimp21
  26. That will select your newly created path on your new transparent layer.  Now, fill that path with a color, either foreground or background, by going to “Edit -> Fill Selection with FG/BG Color”.  I filled mine with red:
    gimp22
  27. What you’ve done is now filled the text path onto your new transparent layer so you can treat the text as a layer.  To test this, do the following: (a) Click on the eye next to the text path in the paths tab, so the path is no longer visible. (b) Click on the “Layer dialog” tab in the “Layers – Brushes” window.  Make sure that your transparent layer is selected and that it is visible by selecting the eye.  (c) Choose your “Ellipse Select” tool from the toolbox and click anywhere outside the currently selected path to turn off all selections.  (d) Then make your background visible by selecting the eye next to it.  What you should see is your background with text around the circle, like this:
    gimp23
  28. You can then choose your “Move Tool” from the Toolbox:
    gimp24
  29. You can now move your new layer around like any other layer.  And there you have it.  You have wrapped text in an image in GIMP.

NOTES:

As noted above, you don’t have to just wrap text in an arc.  You can create all sorts of paths and align text to them.  I drew on this tutorial to figure this out.

 1,568 total views