dimanche 31 mars 2019

How to get an outcome for r plot for a code that implements a beta-delta model

My code for getting a proper plot in R does not seem to work (I am new to R and I am having difficulties with coding).

Basically, using the concept of temporal discounting in the form of beta-delta model, we are supposed to calculate the subjective value for $10 at every delay from 0 to 365.

The context of the homework is that we have to account for the important exception that if a reward is IMMEDIATE, there’s no discount, but if it occurs at any delay there’s both an exponential discount and a delay penalty.

I created a variable called BetaDeltaValuesOf10, which is 366 elements long and represents the subjective value for $10 at each delay from 0 to 365.

The code needs to the following properties using for-loops and an if-else statement:

1) IF the delay is 0, the subjective value is the objective magnitude (and should be saved to the appropriate element of BetaDeltaValuesOf10.

2) OTHERWISE, calculate the subjective value at the exponentially discounted rate, assuming 𝛿 = .98 and apply a delay penalty of .8, then save it to the appropriate element of BetaDeltaValuesOf10.

The standard code given to us to help us in creating the code is as follows:

BetaDeltaValuesOf10 = 0

Delays = 0:365

Code to get subjective value/preference using exponential discounting model:

ExponentialDecayValuesOf10 = .98^Delays*10

0.98 is the discount rate which ranges between 0 and 1.

Delays is the number of time periods in the future when the later reward will be delivered

10 is the subjective value of $10

Code to get subjective value using beta-delta model:

0.8*0.98^Delays*10

0.8 is the delay penalty

The code I came up with in trying to satisfy the above mentioned properties is as follows:

for(t in 1:length(Delays)){BetaDeltaValuesOf10 = 0.98^0*10

if(BetaDeltaValuesOf10 == 0){0.98^t*10}

else {0.8*0.98^t*10} }

So, I tried the code and did not get any error. But, when I try to plot the outcome of the code, my plot comes up blank.

To plot I used the code:

plot(BetaDeltaValuesOf10,type = 'l', ylab = 'DiscountedValue')

I believe that my code is actually faulty and that is why I am not getting a proper outcome for my plot. Please let me know of the amendments to the code and if the community needs any clarification, I will try to clarify as soon as I can.

Aucun commentaire:

Enregistrer un commentaire