0% found this document useful (0 votes)
4 views4 pages

R Implementation Assignment

This R Implementation Assignment for Introductory Statistics requires students to analyze data using R, focusing on organizing, summarizing, and visualizing both categorical and quantitative variables. Students must complete tasks involving frequency tables, descriptive statistics, regression modeling, and interpret results, culminating in a report and R code submission. The assignment is divided into six tasks, each with specific requirements and marking criteria.

Uploaded by

umaimasyed88
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)
4 views4 pages

R Implementation Assignment

This R Implementation Assignment for Introductory Statistics requires students to analyze data using R, focusing on organizing, summarizing, and visualizing both categorical and quantitative variables. Students must complete tasks involving frequency tables, descriptive statistics, regression modeling, and interpret results, culminating in a report and R code submission. The assignment is divided into six tasks, each with specific requirements and marking criteria.

Uploaded by

umaimasyed88
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 Implementation Assignment

Introductory Statistics | Execution-based assignment | Total: 100 marks

Student Name: Roll/ID: Section: ____________


____________________________ ____________________

Submission: R code + report PDF Data entry: Create vectors External file: Not required
directly in R

Purpose
This assignment checks whether you can use R to organize data, summarize categorical and quantitative variables,
construct basic graphs, calculate descriptive measures, assess variation and skewness, and fit a simple regression
model.
R access advisory: If R/RStudio is not installed on your computer, you may use the cloud version through [Link]. A free
Posit Cloud account is suitable for light classroom use, subject to Posit's current usage limits.

Allowed R tools
- Base R functions such as c(), table(), [Link](), barplot(), pie(), hist(), boxplot(), mean(), median(), sd(), quantile(),
IQR(), cut(), lm(), predict(), abline(), [Link](), and round().
- No additional packages are required. If you use an additional package, briefly mention why you used it and still show
the core calculation clearly.

- Use comments in your R code to label each task.

Deliverables
- One R code file named RollNo_Name_R_Assignment.R. The code must run from top to bottom without errors.
- One report PDF containing the required tables, graphs, calculations, and short interpretations.
- One short learning note: mention one small coding issue you noticed or corrected while working, and show the final
corrected line. Keep it to 2-3 sentences.

- Check that the numerical values in your report match the values printed by your R code.

Marking summary
Task Main skill Marks

Task 1 Qualitative data: frequency, relative frequency, percentages, bar chart, pie chart 15

Task 2 Quantitative data: descriptive measures, histogram, grouped table, grouped mean 20

Task 3 Grouped median and grouped mode with step-by-step calculation 15

Task 4 Boxplot, quartiles, IQR, fences, outliers, interpretation 15

Task 5 Coefficient of variation and Chebyshev theorem 15

Task 6 Regression, prediction, residual, Pearson skewness 20

R Implementation Assignment | Introductory Statistics Page 1


Task 1 - Qualitative data: frequency, percentage, bar chart, pie chart (15 marks)
Create your own categorical vector of exactly 24 observations. Choose a small, ordinary record you can reasonably
observe or reconstruct for yourself, such as study activity blocks, preferred drink during the week, transport mode,
phone-use purpose, or meal type. At least three categories must appear.
Example format only - replace it with your own categories and observations:
activity <- c("Study", "Phone", "Study", "Tea", "Walk", "Study",
"Phone", "Study", "Talk", "Walk", "Tea", "Study",
"Study", "Phone", "Tea", "Walk", "Study", "Phone",
"Walk", "Tea", "Tea", "Phone", "Talk", "Walk")

Required work:

- Create a frequency table using table().

- Create a relative frequency table using [Link]().


- Create a percentage table and a pie-angle table. Use angle = frequency / total * 360.

- Draw one bar chart and one pie chart.


- Write four sentences: most common category, least common category, one pattern you notice, and one limitation of
your small dataset.
Marks: vector and code 3, tables 5, graphs 4, interpretation 3.

Task 2 - Quantitative data: raw summary, histogram, grouped table (20 marks)
Create a numeric vector called scores with exactly 30 values. Use one variable that is meaningful to you, such as
minutes of focused study, daily screen pickups, pages read, practice quiz marks, commute minutes, or similar small
measurements. Values should be positive and should show some variation.
Example format only - replace the values with your own numeric values:
scores <- c(67, 74, 71, 82, 59, 76, 88, 64, 70, 73,
78, 61, 69, 84, 90, 55, 72, 77, 80, 66,
75, 68, 79, 83, 62, 71, 85, 58, 74, 81)

Required work:
- Calculate mean, median, mode, minimum, maximum, range, standard deviation, and sample size.

- Draw a histogram and write three sentences about shape, concentration, and unusual values.
- Create grouped classes using cut(). Choose class limits that make sense for your values. Show frequency, midpoint,
and f*x.

- Compute grouped mean manually using sum(f*x) / sum(f), and compare it with the raw mean.
Suggested class-code pattern - adjust breaks to fit your values:
classes <- cut(scores,
breaks = c(30,40,50,60,70,80,90,100),
right = FALSE,
labels = c("30-39","40-49","50-59","60-69","70-79","80-89","90-99"))
freq_scores <- table(classes)

Marks: raw measures 6, histogram and interpretation 4, grouped table 6, grouped mean comparison 4.

Task 3 - Grouped median and grouped mode (15 marks)


Use the grouped frequency table from Task 2. Do not use a built-in grouped median or grouped mode function. Show
your working in R using variables for class limits, class width, frequency, cumulative frequency, and the relevant class.

Required work:

- Create a cumulative frequency column.

- Identify the median class, where cumulative frequency first reaches or crosses N/2.

- Calculate grouped median using: median = l + (h / f) * (N/2 - CF).

- Identify the modal class, the class with maximum frequency.

R Implementation Assignment | Introductory Statistics Page 2


- Calculate grouped mode using: mode = l + h * ((fm - f1) / (2*fm - f1 - f2)).

- Write two sentences comparing grouped median, grouped mode, and raw median.
Marks: median class 3, grouped median calculation 4, modal class 2, grouped mode calculation 4, comparison 2.

Task 4 - Boxplot, quartiles, IQR, and outliers (15 marks)


Use the raw numeric vector scores from Task 2.

Required work:

- Calculate Q1, Q2, and Q3. Use quantile(scores, probs = c(.25, .5, .75), type = 2) so the method is clear.
- Calculate IQR = Q3 - Q1.

- Calculate lower fence = Q1 - 1.5*IQR and upper fence = Q3 + 1.5*IQR.


- List any outliers using R code.

- Draw a boxplot and write three sentences about center, spread, skewness, and outliers.
qs <- quantile(scores, probs = c(.25, .5, .75), type = 2)
iqr_value <- qs[3] - qs[1]
lower_fence <- qs[1] - 1.5 * iqr_value
upper_fence <- qs[3] + 1.5 * iqr_value
outliers <- scores[scores < lower_fence | scores > upper_fence]

Marks: quartiles 3, IQR and fences 4, outlier list 3, boxplot 3, interpretation 2.

Task 5 - Coefficient of variation and Chebyshev theorem (15 marks)


Split your scores vector into two halves: first 15 values and last 15 values. Treat them as two comparable sets.
Required work:
- Compute mean, standard deviation, and coefficient of variation for each half. Use CV = sd / mean * 100.
- State which half is more consistent and explain using CV.

- For the full scores vector, compute Chebyshev intervals for z = 2 and z = 3 using mean +/- z*sd.
- Count the actual percentage of your scores inside each interval using R.
- Compare the actual percentages with Chebyshev's minimum percentages.
first_half <- scores[1:15]
second_half <- scores[16:30]
cv_first <- sd(first_half) / mean(first_half) * 100
cv_second <- sd(second_half) / mean(second_half) * 100

z <- 2
lower <- mean(scores) - z * sd(scores)
upper <- mean(scores) + z * sd(scores)
actual_percent <- mean(scores >= lower & scores <= upper) * 100
cheb_min <- (1 - 1/z^2) * 100

Marks: CV calculation 5, consistency explanation 3, Chebyshev intervals 4, actual percentage comparison 3.

Task 6 - Scatterplot, regression, prediction, residual, Pearson skewness (20 marks)


Create an index variable x for observation number and use your scores as y. This lets you study whether your values
tend to rise, fall, or stay stable across the sequence.
Required work:

- Create x <- 1:length(scores) and y <- scores.

- Draw a scatterplot of x and y, then add the regression line using abline(model).
- Fit a simple regression model using lm(y ~ x).

- Write the fitted regression equation using your intercept and slope.

- Interpret the slope in one sentence and the intercept in one sentence.
- Predict y when x = 10 and calculate the residual for observation 10 using: actual y - predicted y.

R Implementation Assignment | Introductory Statistics Page 3


- Compute Pearson's coefficient of skewness: sk = 3*(mean(y) - median(y)) / sd(y). Interpret it using: sk < -0.5 negative
skewness, -0.5 to 0.5 approximately symmetric, sk > 0.5 positive skewness.
x <- 1:length(scores)
y <- scores
model <- lm(y ~ x)
plot(x, y, main = "Scatterplot with regression line", xlab = "Observation number", ylab
= "Score")
abline(model)

coef(model)
pred_10 <- predict(model, newdata = [Link](x = 10))
resid_10 <- y[10] - pred_10
sk <- 3 * (mean(y) - median(y)) / sd(y)

Marks: scatterplot and model 4, equation 4, slope/intercept interpretation 4, prediction and residual 4, skewness calculation
and interpretation 4.

Required report structure


Part What to include

Cover page Name, roll/ID, section, assignment title, and R environment used (local R/RStudio or
[Link]).

Task 1 Categorical vector, frequency table, relative frequency table, percentage table, pie angles, bar
chart, pie chart, interpretations.

Task 2 Numeric vector, raw descriptive measures, histogram, grouped table, grouped mean
comparison, interpretations.

Task 3 Grouped median and grouped mode calculations, including median/modal class selection.

Task 4 Boxplot, quartiles, IQR, outlier boundaries, outlier list, interpretation.

Task 5 CV comparison and Chebyshev calculation with actual percentage check.

Task 6 Scatterplot, regression equation, slope/intercept interpretation, prediction, residual, Pearson


skewness.

Final check Short learning note and confirmation that the submitted R code runs from top to bottom without
errors.

Brief viva / spot-check preparation


- Be ready to explain how you created your categorical vector and why your categories are valid.

- Be ready to explain one formula you used manually, such as grouped median, grouped mode, coefficient of variation,
Chebyshev interval, Pearson skewness, or residual.

- Be ready to identify which line of code produced any one graph in your report.
- Be ready to run your R code file again if asked.
End of assignment.

R Implementation Assignment | Introductory Statistics Page 4

You might also like