Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data in the following raw CSV file to be read in for the question below: https://raw.githubusercontent.com/pandahappy204/Sample/main/mydata.csv Below Code needed to solve for problem: library(flux) library(rockchalk)

Data in the following raw CSV file to be read in for the question below: https://raw.githubusercontent.com/pandahappy204/Sample/main/mydata.csv

Below Code needed to solve for problem:

library(flux)

library(rockchalk)

library(car)

library(tidyverse)

mydata$VOLUME <- mydata$LENGTH * mydata$DIAM * mydata$HEIGHTmydata$RATIO <- mydata$SHUCK / mydata$VOLUME

mydata$L_RATIO <- log10(mydata$RATIO)

mydata$TYPE <- rockchalk::combineLevels(mydata$SEX, levs = c("F", "M"), "ADULT")

mydata <- mydata %>% mutate(L_SHUCK = log10(SHUCK), L_VOLUME = log10(VOLUME))

mature <- mydata$CLASS %in% c('A4', 'A5')

mydata$TYPE[mature] <- rockchalk::combineLevels(

mydata$TYPE[mature],

levs = c('I', 'ADULT'),

'ADULT'

)

model <- lm(L_SHUCK ~ L_VOLUME + CLASS + TYPE, data = mydata)summary(model)

idxi <- mydata$TYPE == "I"

idxa <- mydata$TYPE == "ADULT"

max.v <- max(mydata$VOLUME)

min.v <- min(mydata$VOLUME)

delta <- (max.v - min.v)/10000

prop.infants <- numeric(10000)

prop.adults <- numeric(10000)

volume.value <- numeric(10000)

total.infants <- sum(idxi)

total.adults <- sum(idxa)

for (k in 1:10000) {

value <- min.v + k*delta

volume.value[k] <- value

prop.infants[k] <- sum(mydata$VOLUME[idxi] <= value)/total.infants

prop.adults[k] <-sum(mydata$VOLUME[idxa] <= value)/total.adults

}

num_infants <- sum(prop_infants <= 0.5)

split_infants <- min_vol + (num_infants + 0.5) * delta

num_adults <- sum(prop_adults <= 0.5)

split_adults <- min_vol + (num_adults + 0.5) * delta

y_loess_a <- loess(1 - prop_adults ~ vol_value,

span = 0.25, family = c("symmetric"))

y_loess_i <- loess(1 - prop_infants ~ vol_value,

span = 0.25, family = c("symmetric"))

smooth_diff <- predict(y_loess_a) - predict(y_loess_i)

cut1 <- vol_value[which.max(smooth_diff)]

a1i <- with(mydata, max(VOLUME[CLASS == 'A1' & TYPE == 'I']))

cut2 <- first(vol_value[vol_value > a1i])

cut3 <- vol_value[which.min(abs(prop_adults + prop_infants - 1))]

cuts <- which(vol_value %in% c(cut1, cut2, cut3))

(Question 1)

Prepare a table in RStudio showing each cutoff along with the following:

1) true positive rate (1 - prop.adults),

2) false positive rate (1 - prop.infants),

3) harvest proportion of the total population

Provide table and R code.

To calculate the total harvest proportions, you can use the 'count' approach, but ignoring TYPE; simply count the number of individuals (i.e. rows) with VOLUME greater than a given threshold and divide by the total number of individuals in our dataset. Remember, prop.adults and prop.infants were variables created above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Applied Calculus

Authors: Stefan Waner, Steven Costenoble

6th Edition

1285415310, 9781285415314

More Books

Students also viewed these Mathematics questions