SC2000 Assignment 1 (A1)
Data Analysis with R
Due date/time: 2pm on Friday, February 27th
Instructions
• Edit only the provided starter file sc2000 a1 starter code.R.
• Replace UXXXXXXXX with your matric number.
• Submit one file: sc2000 a1 <matric>.R.
• Do not print values.
• Store all answers in variables with the exact names specified.
• Use base R only.
• Grading is fully automated.
Dataset Description
Your dataset contains n = 1000 simulated food-centre transactions.
Each row represents one transaction.
Variables
Variable Meaning
txn id Transaction ID
day Day (1–28)
hour Hour (0–23)
stall Stall ID (S1–S20)
payment method cash / card / wallet
items Number of items purchased
spend Total spend (continuous, right-skewed)
queue min Queue time in minutes
rating Rating (1–5, 5% missing)
1
Built-in Structure
• spend is positively skewed.
• Queue times increase during peak hours {11, 12, 13, 18, 19}.
• Ratings decrease with longer queues.
• Your dataset is reproducible via your matric-based seed.
Definition of the Indicator Function
For any logical condition A, the indicator function I(A) is defined as:
(
1 if A is true,
I(A) =
0 if A is false.
The indicator function converts a logical statement into a numerical value.
Example.
is peak hour = I(hour ∈ {11, 12, 13, 18, 19})
This means:
• is peak hour = 1 if the transaction occurs during peak hours.
• is peak hour = 0 otherwise.
Part A — Distribution Diagnostics
A1. Skew Score
mean(spend) − median(spend)
spend skew score =
sd(spend)
A2. Skew Flag
(
1 if spend skew score > 0.1
spend skew flag =
0 otherwise
Part B — Robust Mean Analysis
B1. IQR Upper Fence
spend upper fence = Q75 + 1.5(Q75 − Q25 )
2
B2. Trimmed Mean
Remove observations strictly greater than the upper fence.
Store result in spend mean trimmed.
B3. Robustness Index
spend mean trimmed
robustness index =
spend mean
Part C — Percentile Implementation
Use SC2000 definition:
25
R= (N − 1) + 1
100
Compute spend q25 manual.
C1. Accuracy Flag
percentile accuracy flag = I(|spend q25 manual − spend q25| < 10−6 )
Part D — Peak Queue Effect
D1. Peak Indicator
is peak hour = I(hour ∈ {11, 12, 13, 18, 19})
D2. Normalised Queue
queue min
queue norm =
mean(queue min)
Compute:
mean queue peak norm, mean queue nonpeak norm
D3. Peak Effect Flag
peak effect flag = I(mean queue peak norm > mean queue nonpeak norm)
Part E — Correlation Analysis and Stability
In this section, you will compute and compare several correlations.
3
E1. Spend–Queue Correlation (Raw)
corr spend queue = cor(spend, queue min)
E2. Spend–Normalised Queue Correlation
corr spend queue norm = cor(spend, queue norm)
E3. Scaling Invariance Flag
Since queue norm is a positive scalar multiple of queue min, the two correlations should be
equal up to numerical tolerance.
Define:
corr scaling flag = I(|corr spend queue − corr spend queue norm| < 10−6 )
E4. Trimmed Correlation
Remove the top 5% of spend observations.
Compute:
corr trimmed = cor(spend, queue min)
using the trimmed dataset.
E5. Stability Flag
corr stability flag = I(|corr spend queue − corr trimmed| < 0.1)
E6. Additional Correlations
Compute:
corr queue rating = cor(queue min, rating, use = ”[Link]”)
corr spend rating = cor(spend, rating, use = ”[Link]”)
corr items spend = cor(items, spend)
E7. Correlation Ranking Flag
corr ranking flag = I(|corr items spend| > |corr spend queue|)
4
Part F — Graphical Output
Save the following PNG files (filenames must match exactly):
1. spend [Link]
Histogram of spend.
2. queue boxplot by [Link]
A single figure containing boxplots of queue norm for each hour (0–23).
Requirements:
• All 24 hours must appear in the same plot.
• Use the hour variable as the grouping factor.
• Label the x-axis clearly (Hour 0 to Hour 23).
• The plot must allow visual comparison of queue variation across hours.
3. queue boxplot [Link]
A single figure containing two boxplots placed side by side:
• Non-peak hours
• Peak hours
Requirements:
• Both boxplots must appear in the same image.
• Use different colours for peak and non-peak.
• Provide clear axis labels.
4. spend queue [Link]
Scatter plot of spend vs queue norm, colour-coded by peak vs non-peak.
Requirements:
• Use one colour for peak observations.
• Use a different colour for non-peak observations.
• Include a legend.
Reflection
At the end of your script (as comments only), write at most 120 words addressing the
following in one coherent paragraph:
Using your computed values, briefly comment on:
• Whether spend is skewed and whether the mean appears robust (refer to the skew
score and robustness index).
5
• Whether peak hours meaningfully increase queue time (refer to the normalised means
and peak flag).
• The strength and stability of the correlation between spend and queue min (compare
raw and trimmed correlations).
• Why correlation is invariant under positive scaling (queue norm vs queue min).
• Which relationship is stronger: items--spend or spend--queue, and whether queue
time is negatively associated with rating.
Your reflection must explicitly reference your computed numerical results. Generic state-
ments without values will receive zero credit.
Grading
• Computation (Parts A–E): 75%
• Logical flags: 10%
• Graphical output: 10%
• Reflection: 5%