Home » Arcsine Transformation in R (With Examples)

Arcsine Transformation in R (With Examples)

by Tutor Aspire

An arcsine transformation can be used to “stretch out” data points that range between the values 0 and 1.

This type of transformation is typically used when dealing with proportions and percentages.

We can use the following syntax to perform an arcsine transformation in R:

asin(sqrt(x))

The following examples show how to use this syntax in practice.

Example 1: Arcsine Transformation of Values in Range 0 to 1

The following code shows how to perform an arcsine transformation on values in a vector that range between 0 and 1:

#define vector 
x #perform arcsine transformation on values in vector
asin(sqrt(x))

[1] 0.3217506 0.6119397 0.7151675 0.7853982 0.9911566

Example 2: Arcsine Transformation of Values Outside Range 0 to 1

Note that the arcsine transformation only works on values between the range of 0 to 1. Thus, if we have a vector with values outside of this range, we need to first convert each value to be in the range of 0 to 1.

#define vector with values outside of range 0 to 1
x #create new vector where each value is divided by max value
y #view new vector
y

[1] 0.02564103 0.17948718 0.20512821 0.38461538 0.61538462 1.00000000

#perform arcsine transformation on new vector
asin(sqrt(y))

[1] 0.1608205 0.4374812 0.4700275 0.6689641 0.9018323 1.5707963

Example 3: Arcsine Transformation of Values in Data Frame

The following code shows how to perform an arcsine transformation of values in a specific column of a data frame:

#define data frame
df frame(var1=c(.2, .3, .4, .4, .7),
                 var2=c(.1, .2, .2, .2, .3),
                 var3=c(.04, .09, .1, .12, .2))

#perform arcsine transformation on values in 'var1' column
asin(sqrt(df$var1))

[1] 0.4636476 0.5796397 0.6847192 0.6847192 0.9911566

And the following code shows how to perform an arcsine transformation of values in multiple columns of a data frame:

#define data frame
df frame(var1=c(.2, .3, .4, .4, .7),
                 var2=c(.1, .2, .2, .2, .3),
                 var3=c(.04, .09, .1, .12, .2))

#perform arcsine transformation on values in 'var1' and 'var3' columns
sapply(df[ c('var1', 'var3')], function(x) asin(sqrt(x)))

          var1      var3
[1,] 0.4636476 0.2013579
[2,] 0.5796397 0.3046927
[3,] 0.6847192 0.3217506
[4,] 0.6847192 0.3537416
[5,] 0.9911566 0.4636476

Additional Resources

How to Transform Data in R (Log, Square Root, Cube Root)
How to Perform a Box-Cox Transformation in R
How to Use the Log Function in R
How to Use the Square Root Function in R

You may also like