Rancho
Rancho

Reputation: 93

How to insert Model equation in R

Here is my data,

Sn,Month,Pi,P
1,Jan,163.42,956.12
2,Feb,149.13,956.12
3,Mar,214.02,956.12
4,Apr,148.02,956.12
5,May,42.14,956.12
6,Jun,10.65,956.12
7,Jul,5.72,956.12
8,Aug,9.05,956.12
9,Sep,10.32,956.12
10,Oct,29.72,956.12
11,Nov,61.4,956.12
12,Dec,112.55,956.12

I want to use the following equation in R.

I only need the values of R for each Month, Kindly help.

Upvotes: 0

Views: 57

Answers (2)

Duck
Duck

Reputation: 39595

Maybe I am confused but you want to get the ratio of P:

#Compute month values
df$Pi2overPi <- df$Pi^2/df$P

Output:

   Sn Month     Pi      P   Pi2overPi
1   1   Jan 163.42 956.12 27.93174120
2   2   Feb 149.13 956.12 23.26042432
3   3   Mar 214.02 956.12 47.90670669
4   4   Apr 148.02 956.12 22.91545036
5   5   May  42.14 956.12  1.85727691
6   6   Jun  10.65 956.12  0.11862789
7   7   Jul   5.72 956.12  0.03421997
8   8   Aug   9.05 956.12  0.08566132
9   9   Sep  10.32 956.12  0.11139020
10 10   Oct  29.72 956.12  0.92381542
11 11   Nov  61.40 956.12  3.94297787
12 12   Dec 112.55 956.12 13.24886259

And the total expression:

#Total value
1.74*log(sum(df$Pi2overPi))+1.29

Output:

[1] 9.917266

Or if last constant is inside log:

#Code2
1.74*log(sum(df$Pi2overPi)+1.29)

Output:

[1] 8.642964

Upvotes: 1

Chris Ruehlemann
Chris Ruehlemann

Reputation: 21400

Assuming you have the data in a dataframe called df:

df$logR <- 1.74*log(sum(df$Pi^2/df$P)+1.29))

Upvotes: 0

Related Questions