0% found this document useful (0 votes)
12 views2 pages

Data Analysis with R: Cities Dataset

TP 4 de statistiques

Uploaded by

rtchuidjangnana
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)
12 views2 pages

Data Analysis with R: Cities Dataset

TP 4 de statistiques

Uploaded by

rtchuidjangnana
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

University of Geneva GSEM

Statistics I Fall 2017


Prof. Eva Cantoni Practical 4

Review of Practicals 1-3 and a full data analysis

Goals: The objective of this practical is to review the descriptive statistics, plots and basic
R programming we have learned through the first three practicals. In additoin, a new data
analysis is perfomed to consolidate what has been learned so far, while learning about few
extra possibilities of R.

1 Revision
Revisit practical 1, 2 and 3 (files Practical1.R, Practical2.R, Practical3.R are pro-
vided in the corresponding folders in Chamilo). Make sure you understand what is done
with each command in R.

2 A Full Data Analysis


Import the dataset [Link] in R and store them as a dataframe called Cities. This
dataset contains information on the economic conditions in 48 cities around the world in
1991. The variables contained in the dataset are the following:

• “City” : City name

• “Work ” : Weighted average of the number of working hours in 12 occupations

• “Price” : Index of the cost of 112 goods and services excluding rent (Zurich = 100)

• “Salary” : Index of hourly earnings in 12 occupations after deductions (Zurich = 100)

Since the summary statistics and plots we have learned so far has its suitable variable type,
it is necessary to know what kind of data you have in your file before summarizing or
visualizing it. You can check the type of variables in the Cities dataset with:
str ( Cities )
or with:
class ( Cities $ ...) # ... has to be replaced by a variable name
to get the type for each variable. Use
summary ( Cities )

1
University of Geneva GSEM
Statistics I Fall 2017
Prof. Eva Cantoni Practical 4

to get a basic description of the dataset.

Look at the entire dataset by typing Cities in R. What do you observe?


The dataset contains some missing values, coded NA. Some of the functions (e.g. vioplot)
cannot handle this and would need special treatment, see point 4. below.

To perform your data analysis, consider the following steps:

1. Provide summary statistics for the variables which have suitable type in the dataset.
When appropriate, draw a kernal density plot to check whether their distributions are
symmetric or not.

2. Draw boxplots of all the numerical (continuous) variables into a single graphical win-
dow. You can use the par() function including the option mfrow=c(nrows, ncols)
to create a matrix of nrows by ncols plots that are filled in by row. For example, if
you need plots to be arranged horizontally, let nrows=1.
par ( mfrow = c (1 ,3)) # 3 figures arranged in a row
boxplot ( Cities $ Work , col = " lightsalmon1 " )
# with the default color changed to lightsalmon
boxplot ( Cities $ Price , col = " mediumseagreen " )
boxplot ( Cities $ Salary , col = " goldenrod2 " )
par ( mfrow = c (1 ,1)) # back to the default setting

What can you say about the distribution of each variable by looking only at the
boxplots?

3. Draw histograms of all the numerical (continuous) variables into a single graphical
window. Use here as well the col parameter to change the default settings.
Describe the distribution of the variables with these new information.

4. Draw violin plots of all the numerical (continuous) variables into a single graphical
window. You have to use the function [Link]() here to eliminate the missing values.
par ( mfrow = c (1 ,3)) # 3 figures arranged in a row
vioplot ( na . omit ( Cities $ Work ))
vioplot ( na . omit ( Cities $ Price ))
vioplot ( na . omit ( Cities $ Salary ))
par ( mfrow = c (1 ,1)) # back to the default setting

Describe the distribution of the variables with these new information. Try to change
manually the width of the bandwidth with the parameter h. What do you observe?

5. Compare, via QQ-plots, the empirical distribution of variables Work, Price and Salary
separately with the Gaussian distribution and draw a reference line. Does the Gaussian
distribution fit well?

Common questions

Powered by AI

Methodologically, understanding variable types guides appropriate statistical and visualization techniques. Continuous variables might require histograms or density plots, while categorical variables suit bar plots. Each visualization should match the data type to avoid misinterpretation. Implementing data cleaning, e.g., handling NAs, ensures precision, maintaining integrity across analyses like distribution assessments or economic comparisons.

Importing data into R as a dataframe organizes the information into a structured format where each column represents a variable and each row an observation. This enables straightforward application of R functions to summarize, visualize, and manipulate data, easing complex analyses like comparative statistics and graphical plots, essential for interpreting economic datasets.

Comparing boxplots allows for quick visual assessment of medians, interquartile ranges, and the presence of outliers across variables. For 'Work', 'Price', and 'Salary', differences in central tendency or spread can suggest differing economic conditions. For example, a wider interquartile range indicates more variability, and the presence of outliers could suggest atypical data points, which might identify special cases among cities.

Kernel density plots can be used to visualize the distribution of data and assess whether it is symmetric by checking for a bell-shaped curve. In R, this can be facilitated using the density() function to compute the estimates and the plot() function to visualize it. Checking the symmetry involves observing if the plot is balanced around the central peak.

Manually adjusting the bandwidth in violin plots affects the smoothness of the distribution representation. A smaller bandwidth results in more sensitivity to data fluctuations, showing more detail but possibly over-emphasizing minor variations. Conversely, a larger bandwidth can smooth over important data structures, potentially masking significant features. This directly impacts how the data variability and distribution shape are interpreted.

Missing values in the 'Cities' dataset, coded as NA, need special treatment since functions like vioplot cannot process them directly. The na.omit() function can be used to exclude these missing values before plotting. Not handling missing values effectively can lead to inaccurate visualizations and statistical results, possibly misrepresenting the underlying data distribution.

Descriptive statistics, such as mean, median, and variance, summarize central tendencies and data variability, offering initial insights into economic conditions like average work hours or cost indices. Identifying trends or disparities guides targeted analyses, such as comparing cities to detect underlying economic patterns or differences in living standards, laying ground for more complex analytical inquiries.

The par() function allows for setting graphical parameters in R, enabling multiple plots in a single window via matrix plotting. This efficient use of space facilitates comparative analysis by displaying relationships across variables side-by-side, enhancing data interpretation. Choosing specific arrangements (e.g., horizontal via mfrow=c(1,3)) clarifies the visual story data tells.

QQ-plots can be used to compare the empirical distribution of a dataset to a theoretical Gaussian distribution by plotting quantiles against each other. A good fit is indicated when the data points closely follow the reference line, suggesting that the variable's distribution approximates the Gaussian distribution well. Deviations from this line suggest a poor fit.

Summary statistics provide measures like mean, median, and standard deviation, identifying potential anomalies by showing deviances from typical values. Visualizations like boxplots or histograms reveal anomalies by displaying deviation or distant data points (outliers). Observing these alongside violin plots, which display distribution shape, further helps in confirming whether outliers are genuine data anomalies or errors needing separate analysis.

You might also like