By using R language, the le indexnger.txt records the length and width of the in
ID: 3812708 • Letter: B
Question
By using R language, the le indexnger.txt records the length and width of the index finger of 8
adults.(Length is explanatory variable)
(a) Read in the data set indexnger.txt" and print it out.
(b) Draw a scatterplot of the width and length.
(c) Find out the longest finger lengths of both male and female. Then mark this
two points in the scatterplot in (a). You can use any aesthetic feature you like
as long as these two points can be distinguished from other points.
(d) Draw a new scatterplot, but substitute all the points with letter F" or M"
according to the gender.(Hint: pch = as.character(sex)). For male the female,
conduct the linear regression separately to determine the relationship of width
and length of fingers. Calculate the coefficients of these two models. Then you
can use the results from the linear regression to draw two predicted lines on
the scatterplot above by different line types (One line for male and the other
for female).
Explanation / Answer
To read the dataset, submit the command below, it reads from the file from the mentioned directory. Sep=" " indicates that the space(" ") is the delimiter
df <- read.delim("C:/Users/Documents/R/indexnger.txt", sep=" ")
Print it out- Now that we have the dataset in df, type df and press enter to print the contents of df. the command print(df) can also be used to print the contents of df
df
print (df)
Scatter plot- out of the three variables in df, we just take two variables length,width to the new data frame named input. and the scatter plot is created on input
input <- df[,c('length','width')]
plot (x = input$lenght,y = input$width, xlab = "Length", ylab = "Widthh", xlim = c(1,10),ylim = c(1,10), main = " Length vs Width")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.