Search code examples
rplotstatisticsanalytics

Plotting variable transformation in R


I want to plot a graphic with these variables of mi data set called DSET : NA. ,PI , PC , SPCI

I want to plot the relationship NA.( in Y axis) VS (1/SPCI*(PI+PC)) (in X axis)

I thought that to codify (1/SPCI*(PI+PC) , I(1/(DSET$SPCI) * (DSET$PC + DSET$PI)) and (1/(I(DSET$SPCI)*I(DSET$PC+DSET$PI)) were the same, but I got two different plots.

Here are my two different plots :

enter image description here

enter image description here

So, which one is correct?, or maybe both are incorrect.

EDIT:

The code for both plots are :

plot(I(1/(DSET$SPCI) * (DSET$PC + DSET$PI)),DSET$NA.)
plot(1/(I(DSET$SPCI)*I(DSET$PC+DSET$PI)),DSET$NA.)

My graphics are visible?

SECOND EDIT:

The answer was so easy, I just had to take a look at the X-Axis to realise the values are totally different and make a manual calculation for one value to choose one plot.

In fact, I wanted to know more about the use of the I() operator.


Solution

  • You can find more information about I() function if you type ?I into R.

    I() isolates the contents in the parentheses from other R code.


    I am familiar with I() argument when doing quadratic glm in R.

    For example for model like this:

    f(y) = alpha + beta*x + gamma*x^2
    

    I can choose from two equal expression

    expression y ~ poly(x, 2) or expression y ~ I(x^2)

    Hard to tell if anyone of your plots is correct. You should focus on correct use of parentheses.