Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/cran/KRLS
12 September 2020, 19:32:35 UTC
  • Code
  • Branches (20)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/0.1
    • refs/tags/0.2
    • refs/tags/0.3-1
    • refs/tags/0.3-2
    • refs/tags/0.3-5
    • refs/tags/0.3-7
    • refs/tags/1.0-0
    • refs/tags/R-2.13.2
    • refs/tags/R-2.14.0
    • refs/tags/R-2.14.1
    • refs/tags/R-2.14.2
    • refs/tags/R-2.15.0
    • refs/tags/R-2.15.1
    • refs/tags/R-2.15.2
    • refs/tags/R-2.15.3
    • refs/tags/R-3.0.0
    • refs/tags/R-3.0.1
    • refs/tags/R-3.0.2
    • refs/tags/R-3.0.3
    No releases to show
  • 9597e8e
  • /
  • R
  • /
  • plot.krls.R
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:3af2d5b3421080d241ec0035bd171af23245c52a
origin badgedirectory badge
swh:1:dir:55c1b74116f8d6532a44cca24fa65bde5ffcd11c
origin badgerevision badge
swh:1:rev:9ee4980f0f951956294c84b7f49fe4374e5a432b
origin badgesnapshot badge
swh:1:snp:dd0ef9cc93a5e7a49e321b9136db9970052e4411

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 9ee4980f0f951956294c84b7f49fe4374e5a432b authored by Jens Hainmueller on 10 July 2017, 12:55:59 UTC
version 1.0-0
Tip revision: 9ee4980
plot.krls.R
plot.krls <-
function(x,
         which=c(1:2),
         main="distributions of pointwise marginal effects",
         setx="mean",
         ask = prod(par("mfcol")) < nplots,
         nvalues = 50,
         probs = c(.25,.75),
         ...)
      {
            
        if( class(x)!= "krls" ){
        warning("x not of class 'krls'")
        UseMethod("summary")
        return(invisible(NULL))
        }
     
        d <- ncol(x$X)
        n <- nrow(x$X)
        if(length(probs)!=2){
          stop("length(probs) must be 2")
        }
        
       # check setx
        if(is.numeric(setx)){
          if(length(setx)!=d){
           stop("length(setx) must be equal to number of predictors") 
          }
         } else {
           if(length(setx)!=1){stop("setx must be one of mean or median")}
           if(sum(setx %in% c("mean","median"))<1){stop("setx must be one of mean or median")}
           setx <- apply(x$X,2,setx)
          }
        
nplots <- 0
if(1 %in% which){ nplots <- nplots + 1}
if(2 %in% which){ nplots <- nplots + d}        
   
    if (ask) {
        oask <- devAskNewPage(TRUE)
        on.exit(devAskNewPage(oask))
    }
 
        if(is.null(colnames(x$X))){
          colnames(x$X) <- paste("x",1:d,sep="") 
          } 
        
        # derivatives
        if(is.null(x$derivatives)){
          cat("recompute krls x with krls(...,derivative = TRUE) to plot marginal effects\n")
         } else {
          colnames(x$derivatives) <- colnames(x$X)
         
          if(1 %in% which){ # histograms of partial derivatives
          form <-  as.formula(paste("~",paste(colnames(x$derivatives),collapse="+"),sep=""))
          
          #require(lattice)
          requireNamespace("lattice", quietly = TRUE)
          
          print(lattice::histogram(form,
                    data=data.frame(x$derivatives),
                    breaks=NULL,
                    main=main
                    ,...)
                )
          #if(length(which)!=1){readline("Press any key for next plot")}
          }
         }
          
          if(2 %in% which){  # conditional expectation plots
             lengthunique    <- function(x){length(unique(x))}
             # vector with positions of binary variables
             binaryindicator <- which(apply(x$X,2,lengthunique)==2)
             quantiles <-  apply(x$X,2,quantile,probs=probs)     
             
              for(i in 1:d){
                
                if(i %in% binaryindicator){ # E[Y|X] for binary Xs
                  Xi <- c(min(x$X[,i]),max(x$X[,i]))
                  Newdata <- matrix(rep(setx,2),ncol=d,byrow=T)
                  Newdata[,i] <- Xi
                  
                } else {
                # E[Y|X] plots for cont Xs
                Xi <- seq(quantiles[1,i],quantiles[2,i],length.out=nvalues)
                Newdata <- matrix(rep(setx,nvalues),ncol=d,byrow=T)
                Newdata[,i] <- Xi
                }
                pout      <- predict(x,newdata=Newdata,se=TRUE)
                Ylo <- pout$fit-1.96*pout$se
                Yhi <- pout$fit+1.96*pout$se
                plot(y=pout$fit,x=Xi,
                     xlab=colnames(x$X)[i],
                     ylab=c("E[Y|X]"),
                     ylim=c(min(Ylo) -.25*sqrt(var(pout$fit)),
                            max(Yhi))+.25*sqrt(var(pout$fit)),pch=19
                     )
                arrows(x0=Xi,y0=Ylo,y1=Yhi,length = 0)
                
              }
          }  
          
}





back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API