'Statistical Analysis with mixed numbers

I am working on a Survey for a small project that requires users to respond to some questions by selecting from a set of radio values, such as Strongly Disagree, Agree, Neutral, Agree and Strongly Agree. For these selections, the Radio values are -1, -2, 0, 1, and 2, respectively. Finally, I need to perform some type of analysis on the data. First, I used Python to try to normalized the values, utilizing the Log10 function

import numpy as np

feel = [-1,-2,0,1,2]
for i in feel:
    print( np.log10(i))

The results are not favorable:

-inf
nan
0.0
0.6931471805599453
1.0986122886681098
<ipython-input-35-830bb9e2f96e>:3: RuntimeWarning: divide by zero encountered in log1p
  print( np.log1p(i))
<ipython-input-35-830bb9e2f96e>:3: RuntimeWarning: invalid value encountered in log1p
  print( np.log1p(i))

If I use C# to repeat the Log10 normalization:

List<double> origin = new List<double> { -1,-2,0,1,2};

Program p = new Program(); 
var norm = 0.0;
var denorm = 0.0;

foreach(var item in origin){

    System.Console.WriteLine($"Number: {item}"); 

    norm = p.normalize(item); // 0.2

    System.Console.WriteLine($"Normalized: {norm}");

    denorm = p.denormalize(norm); //12

    System.Console.WriteLine($"Denormalized: {denorm}");
}


public double normalize(double value)
{
    var norm = Math.Log10(value);
    return norm;
}

public double denormalize(double value)
{
    var denorm = Math.Round(Math.Pow(10,value),14); 
    return denorm;
}

I get:

Number: -1
Normalized: NaN
Denormalized: NaN
Number: -2
Normalized: NaN
Denormalized: NaN
Number: 0
Normalized: -∞
Denormalized: 0
Number: 1
Normalized: 0
Denormalized: 1
Number: 2
Normalized: 0.3010299956639812
Denormalized: 2

Is there a finite way to collect Survey data to then normalize and to finally run some analysis for an attitudinal approach?



Solution 1:[1]

The problem with using np.log10 is that there is no root on base 10 for negative numbers. In other words, 10^x = y with y < 0 is not solvable. If you want or need to use that function in particular you will need to sum 3 to all your options. That is, instead of going from -2 to 2 they should go from 1 to 5.

import numpy as np

feel = [1,2,3,4,5]
for i in feel:
    print(np.log10(i))

This outputs:

>>> 0.0
>>> 0.3010299956639812
>>> 0.47712125471966244
>>> 0.6020599913279624
>>> 0.6989700043360189

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Enric Grau-Luque