0% found this document useful (0 votes)
3 views16 pages

Tutorial 2 Practice

This document is an introductory tutorial for R-Instat, focusing on analyzing daily climatic data from Dodoma, Tanzania, from 1935 to 2013. It guides users through data preparation, producing graphs, and saving data, emphasizing the importance of handling missing values. The tutorial encourages further exploration of analyses and invites user feedback for improvements to R-Instat.

Uploaded by

Obedience Nhongo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Tutorial 2 Practice

This document is an introductory tutorial for R-Instat, focusing on analyzing daily climatic data from Dodoma, Tanzania, from 1935 to 2013. It guides users through data preparation, producing graphs, and saving data, emphasizing the importance of handling missing values. The tutorial encourages further exploration of analyses and invites user feedback for improvements to R-Instat.

Uploaded by

Obedience Nhongo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

R-INSTAT INTRODUCTORY

TUTORIAL 2

BY: ROGER STERN, DANNY PARSONS, JAMES MUSYOKA , DAVID STERN AND BERYL WASWA
November 2022
R-INSTAT INTRODUCTORY TUTORIAL 2

CONTENTS

1. The Dodoma Dataset 2


2. Preparing the Data 6
3. Producing the Graphs 11
5. Reflections 14
6. Next steps 15

1
R-INSTAT INTRODUCTORY TUTORIAL 2

1. THE DODOMA DATASET

This tutorial guide follows on from Part 1 of the introductory tutorial. We recommend
starting with Tutorial 1, though this part is independent of the data and steps.

This is daily climatic data from Dodoma in Tanzania, from 1935 to 2013. (Footnote: We are
very grateful to the Tanzania Met Authority who have given permission for these data to be
used for training purposes.)

⮚ If the diamonds data are still in R-Instat then use File > Close Data Book (Fig. 1)
⮚ You will be asked if you are sure. Respond Yes.
Fig. 1 Close Data Book Import from Library

⮚ Use File > Import from Library. Take the option to Load from Instat Collection and
then press Browse.
⮚ Choose Climatic and select the Excel file Climatic_guide_datasets.
⮚ This Excel file has multiple sheets. Choose the one called Dodoma, see Fig. 2

2
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 2 Import Dataset

An initial objective is to provide time series graphs for the annual mean temperatures, both
maximum and minimum. The data are daily and have first to be averaged to an annual level.
Hence dialogues in the Prepare menu will be used, to put the data in the "right shape" for the
analysis.

The data are shown in Fig. 3. There are 28,855 observations.

One difference from the diamonds example in Part 1 is that missing values are immediately
visible in the data.

3
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 3 Dodoma Data

To find out more about the missing values, use Prepare > Check Data > One Variable
Summarise.

➢ Click on the down arrow of the Add button and select Add All from the drop-down
menu.
➢ Click Ok

4
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 4 One Variable Summarise Dialog

The results include the number of missing values. Over 8 thousand values are missing for the
temperature columns. (As this feature was not evident in the similar output in Part 1 it follows
that the diamonds data did not have any missing values.)

The rainfall data in Fig. 3 are from 1935. The station added temperature records later.

⮚ Use the scroll bar and the single arrow at the bottom of the dataset to move through
the data to confirm that the temperatures started in 1958.

5
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 5 Start of the Temperature Data

This indicates that most of the 8 thousand missing temperature data in Fig. 4 are because of
the later start of measuring these elements.
Often preparing the data for analysis takes most of the time. We have tried to make the
Prepare menu in R-Instat as simple to use as possible. We hope you enjoy the process, or at
least the satisfaction of knowing that you are setting yourself up for a successful analysis. And
there is a "silver lining" at the end, as we explain later in the video on Saving the Data.

2. PREPARING THE DATA

The next step is to apply a filter so the data for analysis start in 1958, i.e. when the
Temperature data starts. Many common tasks from the Prepare menu are quickly accessible
through a special right-click menu.

⮚ Put the cursor in the top row (with the names) and right-click
⮚ Choose the Filter Rows from this menu (Fig 6)
⮚ In the Filter dialog, click on the Define New Filter button (Fig 6)

6
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 6: Right Click Menu and Filter Dialog

In the sub-dialog,

➢ Add the Year variable.


➢ Use the drop-down menu to select the > symbol, indicating greater than.
➢ Then enter 1957 by typing or using keypad.
➢ Click the Add Condition button, which will move the condition to the box on the lower
left. If needed you could add multiple conditions to your filter; however, in this
instance we just have this one.
➢ Click Return
➢ Back in the Filter Dialog a summary of your filter will now be visible in the Selected
Filter Preview box. It looks right so click OK.

Fig. 7: Define New Filter

7
R-INSTAT INTRODUCTORY TUTORIAL 2

R-Instat has filtered the data to start when the temperature data starts, so the first row of
data is now 8402. The row numbers are now in red to indicate that there is a filter on.

Fig. 8: Filtered Data Starting in 1958

Now that the filter is in place do the summary again to see if this has significantly reduced the
number of missing values, as expected.

➢ Use the down arrow on the View/Edit Last Dialog icon and select One Variable
Summarise from the list.
➢ It remains as we left it, with all the variables in the Variable(s) to Summarise box, so
just click OK.

Fig. 9: Summary of Filtered Data Starting in 1958

8
R-INSTAT INTRODUCTORY TUTORIAL 2

The missing values in the Temperatures variables have indeed been drastically reduced to
just 230 and 302. Over a period of 55 years (from 1958-2013) this seems like a reasonable
number of missing values. So, we proceed.

The daily data are now ready to be summarized to produce the yearly means.

➢ Open the Prepare > Data Reshape > Column Summaries dialogue

➢ Complete the dialogue by putting tmin and tmax into Variable to Summarise;
and year into the Summarise By receiver.
➢ Tick the option to Omit Missing Values.
➢ Then press the Summaries button to open the sub-dialogue.
Fig. 10: Column Summaries

➢ Complete the sub-dialogue as shown, with only two summaries for the N Not Missing
and the Mean.
➢ Then press Return and OK to produce the summaries.

9
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 11: Column Summaries Sub-Dialog and Results

Fig. 11 shows we now have 2 data frames, one at the daily level and the other with
the annual summaries. This second data frame is the one needed for the analysis
graphs.

In the summaries dialog we ticked Omit Missing Values. The issue of missing values is so
important that almost every function in R offers two main alternatives.

The R default is to be cautious; this corresponds to the missing options check box being un-
ticked. When this is the case, if there is even a single missing value in a year, then the
summary is set to missing.

➢ Try it. Return to the Column Summaries Dialog, either via the menus or by using the

View/Edit Last Dialogs icon in the toolbar .


➢ Untick the Omit Missing Values checkbox.

Lots of years are missing a few values and therefore you can see there are a lot of missing
summaries. In 1965 there were 11 missing days for tmin, so the summary is also missing. (Fig.
12)

Return to the dialogue and tick the missing option, as we did before. This is the bold option.
Now the missing days are omitted, and the summaries are based on the non-missing values.
Now there are no missing summaries because each year had some value.

R-Instat has added some intermediate options, but that’s for another exercise. Here we
continue with the bold summaries, because no year has that many missing values.
10
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 12: Missing Values not Omitted Missing Values Omitted

3. PRODUCING THE GRAPHS

Now we are ready to produce graphs.

⮚ Use Describe > Graphs > Line Plot


⮚ Complete the dialogue as shown for the mean_tmax.
⮚ Use the down arrow on the OK button to select OK & Keep. This will produce the
mean_tmax graph but keep the window open for you to you keep using. (If you closed
the dialogue, that is not a problem. Just use the toolbar icon to re-open it.)
⮚ Next replace mean_tmax with mean_tmin and press OK

11
R-INSTAT INTRODUCTORY TUTORIAL 2

Fig. 13: Line Plot

The blue lines in Fig 14 indicate a clear trend in the temperatures, with the slope in tmin
being more than that in tmax. In more detail, the tmin line is about 16.2 degrees in 1960 and
a degree higher by 2000, so 40 years later. So, the increase is more than 2 degrees per 100
years.

Fig. 14: Line Plots for tmax and tmin

12
R-INSTAT INTRODUCTORY TUTORIAL 2

4. SAVING THE DATA

Before using a different data set save these data, so you can resume later if you want to.

⮚ Go to File > Save As, choose the option Save Data As. This dialog can also be accessed
by using Ctrl + S or the Save… menu option.
Fig. 15: Save Data As

The RDS extension is added, to signify it is saved as an R data file. This is the "silver
lining" we mentioned in Section 1. If done well, the data only have to be organised
once. Then the resulting file, with the two data frames, can be opened in the future,
and the analysis can be continued.

13
R-INSTAT INTRODUCTORY TUTORIAL 2

5. REFLECTIONS

The steps in preparing and then analysing the data were quite short. That is largely
because we gave ourselves a small and clear objective. This resulted in the graphs in
Fig. 14.

The result, here in Fig. 14 may be sufficient, but often stimulate discussion on possible
additions. As an example, Fig 16 shows a similar graph for tmin, but on a monthly
basis. We have also added the equations of the regression lines to the plot, for each
month.

Fig. 16: Monthy Graph for tmin with Equations for Regression Lines

Data are often at multiple levels. This may be, as here, because the level at which the
data were collected, here daily, is different to the yearly level for the analysis, Fig 11.
In other instances, a survey may collect data at multiple levels, for example at

14
R-INSTAT INTRODUCTORY TUTORIAL 2

household and at person level. R-Instat makes it easy organise and analyse data at
multiple levels1.

Finally, our main objective in this tutorial was for users to learn about R-Instat through
this practice. But our reflections are on data and statistical ideas. When using a GUI,
such as R-Instat, it becomes very easy to combine learning this new tool, while
continuing to concentrate on data and statistical issues2.

6. NEXT STEPS

There are more analyses that can be explored with this data in R-Instat and we encourage
you now to try. Feedback and reporting bugs

R-Instat is still under active development with improvements and new features
planned for future versions. We appreciate your feedback to help us improve R-Instat.
There are several ways you can provide feedback:

1. For general feedback contact us via email at:


R-Instat@[Link].
2. Our issues page on our GitHub account can be used to report specific
bugs or suggestions and this is the most direct way to contact the
development team. Our issues page is publicly visible to anyone. It can be
accessed here: [Link]
Click the green New Issue button on the right side to send your message.
When reporting a bug or problem, it’s most helpful if you can be as specific as
possible, and detail how to reproduce the bug. Attach data if possible. You may
be able to include a capture of the completed dialogue. Ideally, (if this is
possible) also paste the R code from the Output window or from the log file.

R-Instat Team, African Data Initiative

15

You might also like