Code Monkey home page Code Monkey logo

pgee's Introduction

PGEE

This fork of the {PGEE} R package is modified from the original by adding the option of applying a ridge / $\text{L}_2$ penalty to the coefficients instead of the usual SCAD penalty.

Installation

You can install the development version of PGEE from GitHub with:

# install.packages("devtools")
devtools::install_github("ad1729/PGEE")

Example

The ridge penalty can be specified by passing the penalty_type = "ridge" argument to the PGEE() call. By default, penalty_type = "SCAD".

library(PGEE)
# library(dplyr)

n <- 1000

set.seed(5)
dat <- dplyr::tibble(
  exposure = rbinom(n, size = 1, prob = 0.6),
  # adding a small factor to the time runif endpoints here to avoid spline warnings 
  # regarding predictions at boundary knots
  time = round(runif(n, min = -3.05, max = 12.05), 2), 
  #time = sample(x = -4:13, size = n, replace = TRUE),
  logodds = -0.1 + (-0.2 * (time ^ 2)) + (0.7 * exposure),
  response = rbinom(n, size = 1, prob = plogis(logodds)), 
  id = factor(rep(LETTERS[1:10], each = 100))
) %>% 
  dplyr::mutate(exposure = factor(exposure, levels = c(0, 1))) %>% 
  dplyr::arrange(id)

# pindex = c(1, 2) indicates that the intercept and exposure terms should not be penalized
mod <- PGEE(
  response ~ exposure + splines2::bSpline(time, knots = seq(-2, 10, 1)),
  data = dat, family = "binomial", corstr = "exchangeable", id = id, 
  lambda = 0.001, scale.fix = TRUE, pindex = c(1, 2), silent = FALSE, 
  penalty_type = "ridge"
)

mod

pgee's People

Contributors

ad1729 avatar

Forkers

econdesousa n-ds

pgee's Issues

Fails when id is a character vector instead of factor.

This following line (implicitly) expects the id column to be a factor variable, and not a character variable.

PGEE/R/PGEE.R

Line 41 in e0838e4

if(!(is.double(id))) id <- as.double(id)

This leads to a warning few lines below

PGEE/R/PGEE.R

Line 48 in e0838e4

maxclsz <-max(avec)

Reprex:

library(magrittr)

letters[1:5] %>% factor() %>% as.double()
#> [1] 1 2 3 4 5

letters[1:5] %>% as.double()
#> Warning in letters[1:5] %>% as.double(): NAs introduced by coercion
#> [1] NA NA NA NA NA

Created on 2023-10-03 by the reprex package (v2.0.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.