Data Mining 2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/22

encourage image

There's no tags or description

Looks like no tags are added yet.

23 Terms

1
New cards

Calculate the product of x and y

x * y

2
New cards

Store the result in a new object called z

z ← x * y

3
New cards

Find the minimum, maximum, length, and variance of myvec.

min(myvec), max(myvec), length(myvec), var(myvec)

4
New cards

The numbers below are the first ten days of rainfall amounts in 1996. Read them into a vector using the c() function.

rainfall ← c(put the first number here, put the second number here, ...)

5
New cards

Type the code for the mean rainfall, how about the standard deviation?

mean(rainfall)

sd(rainfall)

6
New cards

Which day saw the highest rainfall (write code)?

which.max(rainfall)

7
New cards

How do we write comments in an R script?

# This is a comment

8
New cards

You have measured five cylinders, their lengths are: 2.1, 3.4, 2.5, 2.7, 2.9 and the diameters are : 0.3, 0.5, 0.6, 0.9, 1.1

Write the code for the correlation between lengths and diameters (use the cor function)

lengths ← c(2.1, 3.4, 2.5, 2.7, 2.9) diameters <- c(0.3, 0.5, 0.6, 0.9, 1.1) cor(lengths, diameters)

9
New cards

You have measured five cylinders, their lengths are: 2.1, 3.4, 2.5, 2.7, 2.9 and the diameters are : 0.3, 0.5, 0.6, 0.9, 1.1.

Write the code for the volume of each cylinder (V = length * pi * (diameter / 2) 2 ).

volume ← lengths * pi * (diameters / 2)^2

10
New cards

Draw 10 random letters from the lowercase alphabet, and sort them alphabetically (Hint: use sample and sort). The solution can be one line of code.

sort(sample(letters, 10))

11
New cards

install.packages("car")

install.packages("car")

12
New cards

Write the code to read in the dataset "Cereals.csv", look at the first few rows with head and inspect the data types of the variables in the dataframe with str.

Cereals ← read.csv("Cereals.csv") head(Cereals)\str(Cereals)

13
New cards

Given the dataset : titanic ← read.table("titanic.txt", header=TRUE)

Write the code to convert the 'Name' (passenger name) variable to a 'character' variable, and store it in the dataframe.

titanicName←as.character(titanicName ← as.character(titanicName)

14
New cards

Make a new variable called 'Status', based on the 'Survived' variable already in the dataset. For passengers that did not survive, Status should be 'dead', for those who did, Status should be 'alive'. Make sure this new variable is a factor. Use "ifelse".

titanicStatus←factor(ifelse(titanicStatus ← factor(ifelse(titanicSurvived == 0, "dead", "alive"))

15
New cards

Create a scatter plot showing the relationship between the variables mpg (miles per gallon) and hp (horsepower). Add a title, axis labels, and use a color different from the default.

plot(mtcarshp,mtcarshp, mtcarsmpg,

main = "Miles per Gallon vs. Horsepower",

xlab = "Horsepower",

ylab = "Miles per Gallon (MPG)",

col = "blue",

pch = 19)

16
New cards

Create a line plot showing the relationship between wt (weight) and mpg (miles per gallon). Make sure to customize the plot with a title, axis labels, and a line color of your choice.

plot(mtcarswt,mtcarswt, mtcarsmpg,

type = "l",

main = "Miles per Gallon vs. Weight",

xlab = "Weight (1000 lbs)",

ylab = "Miles per Gallon (MPG)",

col = "red")

17
New cards

Create a histogram of the mpg variable (miles per gallon). Use the viridis color palette for the fill color. Customize the bin width and add appropriate labels.

ggplot(mtcars, aes(x = mpg)) + geom_histogram(binwidth = 3, fill = viridis(1),

color = "black") +

labs(

title = "Distribution of Miles per Gallon",

x = "Miles per Gallon (MPG)",

y = "Frequency" ) +

theme_minimal()

18
New cards

Create a box plot comparing mpg across the number of cylinders (cyl). Use viridis to color the plot by the number of cylinders. Customize the plot with a title, axis labels, and theme.

ggplot(mtcars, aes(x = factor(cyl), y = mpg, fill = factor(cyl))) +

geom_boxplot() +

scale_fill_viridis_d() +

labs(

title = "Miles per Gallon by Number of Cylinders",

x = "Number of Cylinders",

y = "Miles per Gallon (MPG)",

fill = "Cylinders" ) +

theme_minimal()

19
New cards

Create a bar chart that shows the count of cars with different numbers of cylinders (cyl). Customize the plot with a title, labels, and choose a color palette of your preference (e.g., viridis, brewer, etc.).

ggplot(mtcars, aes(x = factor(cyl), fill = factor(cyl))) + geom_bar() +

scale_fill_viridis_d() +

labs(

title = "Count of Cars by Number of Cylinders",

x = "Number of Cylinders",

y = "Number of Cars",

fill = "Cylinders" ) +

theme_minimal()

20
New cards

For this question, use the pupae data. Write the code that perform a simple linear regression of Frass on PupalWeight

model ← lm(Frass ~ PupalWeight, data = pupae)

21
New cards

What is the code for the summary of the model?

summary(model)

22
New cards

Using the Pulse data, write the code to fit a multiple linear regression of Pulse1 against Age, Weight and Height.

model ← lm(Pulse1 ~ Age + Weight + Height, data = Pulse)

23
New cards

Using the Pulse data once more, write the code that builds a model to see if Pulse2 can predict whether people were in the Ran group. Make sure that Ran is coded as a factor.

PulseRan←as.factor(PulseRan ← as.factor(PulseRan) model <- glm(Ran ~ Pulse2, data = Pulse, family = binomial) summary(model)