Module # 9 assignment- prop tables

 3/11/25

In this assignment, you have two questions.

1. Your data.frame is

> assignment_data <- data.frame( Country = c("France","Spain","Germany","Spain","Germany", "France","Spain","France","Germany","France"), age = c(44,27,30,38,40,35,52,48,45,37), salary = c(6000,5000,7000,4000,8000,5500, 4500, 6000, 7500, 5000), Purchased=c("No","Yes","No","No","Yes", "Yes","No","Yes","No","Yes"))

Generate simple table in R that consists of four columns: Country, age, salary and purchased.





2. Generate contingency table also known as r x c table using mtcars dataset i.e. data(mtcars)

assignment9 <table(mtcars$gear, mtcars$cyl, dnn=c("gears", "cylinders")

2.1 Add the addmargins() function to report on the sum totals of the rows and columns of assignment9 table
>addmargins(assignment9)

2.2 Add prop.tables() function, and report on the proportional weight of each value in a assignment9 table

The proportional table shows the fraction of each cell relative to the total number of observations (sum = 32). The highest proportion, 0.375, is for cars with 3 gears and 8 cylinders, indicating that this combination is the most common. Cars with 4 gears and 4 cylinders make up 25% (0.250) of the dataset, showing that this combination is also relatively frequent. Some values are zero, meaning there are no cars with 4 gears and 8 cylinders, highlighting a gap in the dataset.

2.3 Add margin = 1 to the argument under prop.table() function, and report on the row proportions found in assignment9 table.

The row proportions table provides insight into how each gear category distributes among the different cylinder counts. A significant 80% of cars with 3 gears have 8 cylinders, demonstrating a strong preference for this combination. In contrast, 66.67% of cars with 4 gears have 4 cylinders, while 33.33% have 6 cylinders, suggesting that 4-gear cars tend to have smaller engines. The 5-gear cars are more evenly distributed, with 40% having 4 cylinders, 20% having 6 cylinders, and another 40% having 8 cylinders, indicating a more balanced spread across cylinder types.







This week’s assignment was pretty straightforward and really informative. It was easy to navigate through the different functions in R, like table()addmargins(), and prop.table(), and they made analyzing categorical data super clear. Breaking down the proportions and understanding the relationships between variables was pretty intuitive. Overall, this was a great hands-on way to learn, and I liked how practical it was!








Comments

Popular posts from this blog

Module # 7- Regression models

Final Project

Module #5- Correlation Analysis