Exploring and presenting data in R

Click here to view the visual representation

I am seeking assistance in translating the following JavaScript code into R and displaying the values at each iteration:

r=4
q=0.02
V=0.01;
S=0.1;
U=0.89;
for(i<200){
     i++;
     v = V;
     s = S;
     u = U;
     V = r*v*s;
     S = s - r*v*s + q*u;
     U = 1 - v - s;
 }

If you have expertise in both languages, your help would be greatly appreciated. Thank you!

Answer №1

Here is my preferred method to accomplish this task using R:

n = 150
r = 3
q = 0.05
V = numeric(n)
S = numeric(n)
U = numeric(n)
V[1] = 0.02
S[1] = 0.15
U[1] = 0.83
for (i in 2:n) {
    V[i] = r * V[i-1] * S[i-1]
    S[i] = S[i-1] - r * V[i-1] * S[i-1] + q * U[i-1]
    U[i] = 1 - V[i] - S[i]
}
result = cbind(V, S, U)

Each cycle's outcome is stored in rows of result. Please note that the calculation for U[i] differs here from your initial input, though it aligns with the equation you provided in the image.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method for determining the conditional expectation in a Weibull model?

I am interested in finding the conditional expectation of the Weibull model. Specifically, I want to estimate the remaining tenure of a client by examining random moments (time = t) within their total tenure. To do this, I have calculated the total tenure ...

Guide to applying a personalized activation function within a neural network on R

I'm a novice at R and I'm currently trying to create a neural network for regression purposes. I've decided to utilize the neuralnet library to build my neural network, which has various arguments including act.fct. act.fct This is a diffe ...

Web Inspector shows no trace of HttpOnly Cookies

My current project involves implementing user authentication for a website using the MERN stack, and I have opted to utilize JWT tokens stored as HttpOnly cookies. Interestingly, when I made the request via Postman, the cookie was sent in the "Set-Cookie" ...

Transform a JSON object into a customized array format with the help of Angular 5 or plain JavaScript

I have a JSON dataset that appears as shown below. [{ {name: "box: 122",x=["2018-01-12T00:01:56.480Z", "2018-01-12T00:05:58.116Z", "2018-01- 12T00:10:00.379Z"], y=[0, 3, 5]}, {name: "box: 125",x=["2018-01-12T00:01:56.480Z", "2018-01-12T00:05:58. ...

Interactive data visualization with hover-over details

I am utilizing datamaps to showcase the countries of the world, however, I want the graph to be centered. The issue arises when I hover over a country and the pop up appears all the way to the left, aligned with where the country would be if it wasn't ...

Investigating radio button validation using Javascript ES6 syntax

I have been attempting to update my code to use ES6 syntax and I'm perplexed as to why my form's radio buttons and checked checkboxes are not registering as true when selected. Even if a user picks one of the options, I still receive an error mes ...

Is there a way to determine whether a mouse-down event took place on the scroll-bar or elsewhere within the element?

Looking for a solution with my HTML div acting as a canvas containing various objects. The issue lies in the fact that when attempting to draw a selection rectangle by dragging with the mouse, if scroll bars appear due to the large size of the canvas, scr ...

A step-by-step guide on setting up an event listener for dynamically generated HTML using JavaScript objects

In my JavaScript code, I am creating object instances that include HTML elements in the form of buttons. These buttons are dynamic and have words generated dynamically as well. I want these buttons to execute certain functions when clicked. The challenge I ...

Utilizing Regular Expressions in AngularJS to validate name, a 10-digit mobile number, and a 12-digit number through the ng-blur event and match

I am struggling to validate the three inputs mentioned above and having trouble using the right functions. Can someone please assist me with this? Here is the HTML code for the 3 inputs: <input id="name" ng-model="user.name" ng-blur="checkIfNameIsVali ...

Strip excess white space from a complex string using Javascript

I have the following sets of strings: 14/04/22 10:45:20 12.08N 87.65W 15.0 2.9ML Frente a Corinto 14/04/21 11:05:34 12.10N 87.70W 140.0 3.5MC Cerca de Masachapa 14/04/22 09:00:09 12.35N 86.44W 12.4 1.3ML Cerca del volcan Momotombo 14/04/21 23:33:37 1 ...

Sorting numeric ID columns in a Bootstrap table

I've implemented the Boostrap table to display data from my database on my admin page. I saved an array into a json file, and then used the following code to populate the table: <div class=\"row\"> <div class=&bsol ...

Exploring Angular's capabilities with filtering and handling $http promises

Having an issue with filtering data from a JSON file that contains an array of 20 objects. Within my factory, I have implemented two functions: function fetchData() { return $http .get('mock.json') .success(_handleData) ...

Overlap in Shield UI Bar Chart

I am looking to create a unique bar chart using Shield UI that features two bars overlapped, rather than side by side. I do not want the total Y axis value displayed. While an area chart accomplishes this, I am specifically interested in achieving this e ...

The steps to properly load "child.vue" into the correct position within "parent.vue" are as follows

Currently I am developing a single page web application using Vue.js. This app consists of 4 "page.vue" files, each with a right and left child .vue component nested inside. For instance, the Page1.vue file is structured as follows (omitting style and scr ...

What are some techniques for animating SVG images?

Looking to bring some life to an SVG using the jQuery "animate" function. The plan is to incorporate rotation or scaling effects. My initial attempt with this simple code hasn't yielded the desired results: $("#svg").animate({ transform: "sc ...

Switch between pages within a reactjs application by utilizing react router

Greetings! I am currently diving into the world of reactjs and experimenting with navigation from one page to another by simply clicking on a link through react router. In my home.js file, I have listed out some interesting places and I aim to click on one ...

Whenever I find myself being redirected to the login page, my goal is to eliminate the bottomTab from view

I'm looking to eliminate the bottom tab when I land on the login page, even though I've set it up for all pages. However, whenever I click on the login button, the tab remains visible. Here is my current code: import React, { useContext } from & ...

Exploring the process of sending a nested object using jQuery AJAX

Hey there, I'm currently facing an issue while trying to send the data from my form to the API. The model in the API has relations with other models and I need to figure out how to properly format the data from my form into an array. When I attempt to ...

Is your preference selecting made a breeze by dragging the input field?

Looking to create a form that allows users to indicate their preference between Option A and Option B by dragging a slider. I know there must be a library out there that already does this, but I can't seem to figure out what it's called to searc ...

Sending values to URL using the <a> tag in HTML

I currently have the selected language stored in a variable (var lan= urlParam('language')). I am trying to pass this language as a parameter (without PHP) in a URL within an "a" tag, like so: <a href="http://hotelscombined.sitewish.gr/HotelN ...