By now, you are getting very familiar with the JASP workspace,
you know how to set variables, and how to select data,
but our next skill set is very important: how do you take existing variables and
use them to create new variables?
For this example we continue using the JASP
data file called "Kitchen Rolls". If you still have it open from the
previous video, then carry on, but if not, click on the main menu
icon -> open -> data library and choose
t-tests. Select the version of the kitchen rolls data set
with the JASP icon in the corner.
We are going to use existing variables to create
new variables.
If we were doing this in SPSS, we would use the command
Transform -> Compute Variable. We would create a new variable by first
giving the new variable a name and then
creating a formula. This would be a total score,
adding up four variables.
We can make it a mean by dividing this total by 4.
This would create a new variable that we
could use in further analysis.
Now let me explain why we might do this. Many things in the world are simple to
measure, such as the height of a structure,
or the weight of a person. Then there are things that we know exist
but cannot be measured directly, such as intelligence, personality,
or level of satisfaction with your job. Scientists create ways to measure these
theoretically-derived conceptions that we call "Constructs."
"Job satisfaction" is a construct. It can't be measured in inches or pounds,
but we have evidence that it exists and we can construct a way to measure it.
Theoretically, your overall job satisfaction may comprise
multiple smaller constructs (or sub-scales) like your satisfaction with
your coworkers, your boss, your pay, or
the benefits. Each of these sub-scales is discrete - or distinct from each other.
You can love your co-workers, but hate your boss,
and be moderately satisfied with your pay.
Each subscale will be measured using three or more
"Items": individual questions asking you about your satisfaction with
pay, each in a slightly different way.
And each of these items will be measured with a Likert scale
perhaps ranging from 1 to 5, or 1 to 7
We are going to focus on this array of ordinal data
labeled "NEO". Now, these are actually personality items, but we're going to
choose four of them to stand in for our pay satisfaction
subscale items. Right now, they are properly labeled as
ordinal, but their being categorical will
create a problem for us later, when we want to do math with them
As we learned in the last video, if you're going to do math,
our variables need to be set to scale.
Change item 2 from ordinal to scale. Now do the same for items 3,
5, and 8. Any time that you plan to add, or
multiply, or do any kind of math, set the level of measurement to scale,
also known as "continuous".
First, we're going to create a total score,
the sum of all four items in our supposed subscale,
"Satisfaction with pay". Click on the black plus sign in the
upper right corner. Ee're going to create a computed column
called "Tota"l using a drag and drop formula,
with the new variable being set to scale: click to create the column.
It will be added as a new column at the right end of the data set.
Drag and drop item 2, then plus sign, now click on
item 3, (that is a quicker way to move a variable),
plus sign, double click on item 5... well, that added item 5 twice,
we don't need that. Let's delete it. Drag the second item 5 to the trash
(or the bin, if you prefer) to be rid of it. Click the plus sign and add
item 8. We are now ready to compute column this is the sum
or total score of the 4 items. Now we will create a mean. We could
compute it with its own formula, but I want to show you how we can use a
previously created variable in yet another new formula.
Click on the black plus sign... call the new variable "Pay",
because this is the average satisfaction with pay subscale.
Note that if you want to learn more, you can open the documentation
and watch brief videos and read
explanations.
Click to create column.
Let's use the "Total" that we just created and then divide it by 4
Dividing the total by 4 calculates the mean.
You can also use this technique to return logical values.
Create a nominal text variable called "Sex 2",
in which we ask if Sex = F.
JASP returns the true and false logicals.
Notice that - like R - the values are case sensitive. so if you ask if Sex = f,
all returned values are FALSE
But what if you need numbers such as 1 and 0 for doing a logistic regression?
This time, create a scale variable called "Sex 3",
in which we ask if Sex = F
the resulting variable consists of 1 and 0, where females are assigned 1
(or true) and males are assigned 0 (or false).
I can also use formulas that calculate the meanof a column
Here i have some data for a set of ages, but
I have some missing data. I'm in a hurry, so i want to replace
all of the missing values with the mean of all of the remaining scores.
...and please, please no nasty comments about mean imputation...
... we're just learning here. Create a new scale variable called
"ageIMPUTE"
Use the "replaceNA" function
to replace the missing values in Age
with the mean of all of the Age scores.
Or I could create an entirely new distribution
called "Normal"
This is a normal distribution with a mean of 0 and a standard deviation of 1
If you want to remove a calculated column,
click on the function sign to select the variable
and then this small trash can, or bin
If you already suspect that you see a lot of
overlap with R, then you are correct. In fact, on any of the
calculated columns, you can click on the R icon
to see the code that is being used this code cannot be edited directly but
you can copy it and paste it and then create a new
variable using the R code option
and copy code into JASP
This, of course, is a total, but you can edit the
R code and now we have a mean.
With R, there are multiple ways to do everything,
we could use our "rowMeans" command
and set our variables as a data frame to calculate a mean...
or we could use the "apply" function, again setting our variables as a data frame.
If you're familiar with coding in R, then you can use your coding skills,
and this example, to calculate other scores,
such as converting feet to meters.
and, of course, you can create new variables using R code of your own
Click on the black plus sign to add a computed column. Our new column would be called "BMI"
using R code and the new variable will be scale
In this data set, I have data for height in inches and
weight in pounds. Remember that R is a calculator, so we
can do the math directly, but we have to type the names of the
variables. I can compute BMI using this formula: 703 * (weight/height^2)
If you have followed along with these first five videos, you are now very
familiar with the JASP workspace, you know how to set variables, and how to
select data, and you now know how to create new
variables, as needed. So i suppose that we should
explore the multiple ways that we can export
data or results out of JASP
Hey, you want a quick peek behind the scenes?
Let me show you what's literally behind the scenes...
I couldn't do it without you, buddy.