#Normalizing transformations to reduce positive skew
# Power transformations for UFOV2
# Then evaluating skew of the transformations

#Notice that for the reciprocal or inverse transformation, because it reflects distributions (i.e., highest
#value becomes the smallest) I did a quick re-reflection (here, multiply the transform by minus 1)

ufov_subset$sqrtUFOV2 <- sqrt((ufov_subset$UFOV2))
ufov_subset$logUFOV2 <- log((ufov_subset$UFOV2))
ufov_subset$invUFOV2 <- -1*(1/(ufov_subset$UFOV2))


# Blom (Rank-based, opportunistic) normalizing transformation for UFOV2
# Normalization

#install.packages('RNOmni')
library(RNOmni)

ufov_subset$blomUFOV2<-rankNorm(ufov_subset$UFOV2, k = 3/8)

# Dealing with negative skew

#We will begin by reflecting the variable from negative to positive skew.
#We do this by finding the current maximum, adding one to it, and subtracting all values from max+1
#Reflecting: New variable is ((old maximum + 1) - oldvar)
#Confirm that the new minimum is 1.0


library(psych)

describe(walkint$Walk)
##    vars   n mean sd median trimmed mad    min   max  range  skew kurtosis   se
## X1 1 957 50 10 53.21 52.01 5 -48.62 58.01 106.63 -3.31 17.3 0.32
walkint$refWalk<-59.01 - walkint$Walk

describe(walkint$refWalk)
##    vars   n mean sd median trimmed mad min    max  range skew kurtosis   se
## X1 1 957 9.01 10 5.8 7 5 1 107.63 106.63 3.31 17.3 0.32

#Normalizing power transformations. Notice that sqrt and log are
#re-reflected (by means of the minus one pre-multiplier)
#back into original direction of the original Walk variable
#Notice that since the inverse already reflects the distribution, we
#leave it alone


walkint$sqrtWalk <- -1* sqrt((walkint$refWalk))
walkint$logWalk <- -1*log((walkint$refWalk))
walkint$invWalk <- (1/(walkint$refWalk))