rchisq Example

Last updated on
26 July 2020

Let's start with creating a web app that generates random observations from a Chi-squared distribution. This will be the simplest app since it requires no dataset and does not generate images. You can see the R function rchisq requires n, which is the number of observations to generate and df, the degrees of freedom.

We can start by duplicating rnorm which comes prepackaged with the AWS image and has roughly the same structure we need for rchisq. Go to the webform administration page at /admin/structure/webform or use the Admin menu to select Structure -> Webform. When Duplicate is selected from the dropdown, you will be presented with modal to title and describe the webform.

Quadstat screenshot

Once the title and description has been given, you will be given the opportunity to add additional elements or delete existing ones. The first thing you will notice is the R element with machine name r. Every Quadstat web app requires this input. We can use the R element to create high-level instructions for R. Click on Edit from the dropdown. You can see the Default Value textbox under Advanced has something like this:

rnorm($n, $mean, $standard_deviation);

This is the R function rnorm that creates random observations from a Normal distribution. Let's replace this value Chi-squared distributions inputs like this:

rchisq($n, $df)

All variables must be lower case with the exception of X, which denotes the selected dataset. The dfr variable is also available and represents the selected data as an R data frame. In general, variables that depend on user input are preceded with a dollar sign.

The app is not quite ready to run yet. We will need to create inputs for df (n is already inherited from rnorm). Click "Add Element." We will select "Number" from Advanced Webform element list. We can title the df element anything we wish but the machine name must be df since that is what we we used in our R function above. We can also set the min and max to arbitrary values and set step to 1.0 since this is an integer. Once this is completed, we can delete the inputs for mean and standard deviation since they are not used in a Chi-squared distribution. The Webform 5 module has so many additional features, too many to discuss here. Site administers are encouraged to explore the features on their own.

We are now ready to create the application wrapper for this webform. Create a new content of type Operation from the admin toolbar. Title it, select the webform we just created from the downdown and also give instructions on how to use the app for your readers if necessary. If app has been configured properly, you will see random observations when you fill out and submit the form.

Please feel free to file a support request at the Drupal Quadstat project page if you need help. If you're not seeing output like this, feel free to open a support request.

Help improve this page

Page status: No known problems

You can: