Posts

Linear model fitting for regression: Basics and Variation

Linear model (simple forms) fitting I use mtcars dataset to construct some basic regression models and fit those. # convert available data to use in fitting mtcars_reg_df <- mtcars %>% rownames_to_column("carnames") %>% as_tibble() %>% mutate_at(c("gear", "am", "vs", "cyl"), as.

Logistic Regression: Part I - Fundamentals

Likelihood theory Probit models were the first of those being used to analyze non-normal data using non-linear models. In an early example of probit regression, Bliss(1934) describes an experiment in which nicotine is applied to aphids and the proportion killed is recorded.

Logistic Regression: Part II - Varietal adoption dataset

Binary classifier using categorical predictor Let’s say we have two variable – survey response of farmer to willingness to adopt improved rice variety (in YES/NO) and them having been trained earlier about agricultural input management (in trained/untrained). Read in the data and notice the summary.

Paste together multiple columns

# # paste together dataframe columns by column index # take the following df df <- data.frame(my_number = letters[1:5], column_odd1 = rnorm(5), column_even1 = rnorm(5), column_odd2 = rnorm(5), column_even2 = rnorm(5), column_odd3 = rnorm(5), column_even3 = rnorm(5)) df %>% select(1) %>% bind_cols(data.

Not so fun with Nepalese flag

Anatomy of flag The anatomy of flag is well described in tipsntricks/readresort section but the quirks of constructing it are not. I will be updating attending to complete the graphics as soon as I learn more. So far, only this ugly shape is what I have here to show;

Piecewise Linear Function: An Introduction

Definition and meaning Wikipedia defines a piecewise linear function as: “a function defined on a (possibly unbounded) interval of real numbers, such that there is a collection of intervals on each of which the function is an affine function”

The birthday problem: Non analytical solution

# Birthday problem crossing(n = 2:100, x = 2:4) %>% mutate(probability = map2_dbl(n, x, ~pbirthday(.x, coincident = .y))) %>% ggplot(aes(n, probability, color = factor(x))) + geom_line() + labs(x = "People in room", y = "Probability X people share a birthday", color = "X") # Approximating birthday paradox with Poisson distribution crossing(n = 2:250, x = 2:4) %>% mutate(combinations = choose(n, x), probability_each = (1/365)^(x-1), poisson = 1-dpois(0, combinations * probability_each), pbirthday_x = map2_dbl(n, x, ~pbirthday(.

Making Summary Tables in R

Background General purpose tables Summary tables rtables package qwraps2 package gtsummary package Background Table output of R is one of the richest and satisfying to use feature. Rmarkdown format provides loads of package support to create, format, and present tables beautifully.

Tidytuesday: Claremont Run, X-men Characters

X men characters Data dictionary explore Table 1: Data summary Name Piped data Number of rows 308 Number of columns 9 _______________________ Column type frequency: character 8 numeric 1 ________________________ Group variables Variable type: character

Array operation: Outer product

Incidentally, I ran into outer product function outer today. It is extremely powerful function, in that it computes all combinations of product of two objects. One simplest and obvious demonstration is the multiplication table of numbers. 😄 We can show multiplication table of numbers 1 through 12 each multiplied 1 through 10.