เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

binomial family argument

The big difference between running a linear regression with lm() and running a logistic regression with glm() is that you have to set glm()'s family argument to binomial. binomial() is a function that returns a list of other functions that tell glm() how to perform calculations in the regression. The two most interesting functions are linkinv and linkfun, which are used for transforming variables from the whole number line (minus infinity to infinity) to probabilities (zero to one) and back again.

A vector of values, x, and a vector of probabilities, p, are available.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Intermediate Regression in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Examine the structure of the binomial() function. Notice that it contains two elements that are functions, binomial()$linkinv, and binomial()$linkfun.
  • Call binomial()$linkinv() on x, assigning to linkinv_x.
  • Check that linkinv_x and plogis() of x give the same results with all.equal().
  • Call binomial()$linkfun() on p, assigning to linkfun_p.
  • Check that linkfun_p and qlogis() of p give the same results.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Look at the structure of binomial() function
___

# Call the link inverse on x
linkinv_x <- ___

# Check linkinv_x and plogis() of x give same results 
___

# Call the link fun on p
linkfun_p <- ___

# Check linkfun_p and qlogis() of p give same results  
___
แก้ไขและรันโค้ด