Skip to content

Instantly share code, notes, and snippets.

@BioSciEconomist
BioSciEconomist / reg matrice.r
Created November 1, 2016 19:20
Matrix Algebra for Regression
# to support: http://econometricsense.blogspot.com/2011/11/basic-econometrics-in-r-and-sas.html
#------------------------------------------------------------
# regression with canned lm routine
#------------------------------------------------------------
# read in data manually
x <- c(1,2,3,4,5) # read in x -values
y <- c(3,7,5,11,14) # read in y-values
@BioSciEconomist
BioSciEconomist / gradeint descent.r
Created November 5, 2016 17:22
Gradeint Descent
# ----------------------------------------------------------------------------------
# |PROGRAM NAME: gradient_descent_R
# |DATE: 11/27/11
# |CREATED BY: MATT BOGARD
# |PROJECT FILE: http://econometricsense.blogspot.com/2011/11/gradient-descent-in-r.html
# |----------------------------------------------------------------------------------
# | PURPOSE: illustration of gradient descent algorithm
# | REFERENCE: adapted from : http://www.cs.colostate.edu/~anderson/cs545/Lectures/week6day2/week6day2.pdf
# |
# ---------------------------------------------------------------------------------
@BioSciEconomist
BioSciEconomist / ex bayesian tobit.r
Created November 5, 2016 22:01
Bayesian Tobit Model
# ------------------------------------------------------------------
# | PROGRAM NAME: ex_bayesian_tobit
# | DATE: 9/17/11
# | CREATED BY: Matt Bogard
# | PROJECT FILE: http://econometricsense.blogspot.com/2011/09/bayesian-models-with-censored-data.html
# |----------------------------------------------------------------
# | PURPOSE: comparison of models for censored dependent variables
# | 1 - least squares
# | 2 - tobit model
# | 3 - bayesian model
@BioSciEconomist
BioSciEconomist / bayesian econometrics.r
Created November 5, 2016 22:03
Elements of Bayesina Econometrics
# ------------------------------------------------------------------
# | PROGRAM NAME: EX_BAYESIAN_ECONOMETRCS
# | DATE: 9-15-11
# | CREATED BY: MATT BOGARD
# | PROJECT FILE: http://econometricsense.blogspot.com/2011/09/elements-of-bayesian-econometrics.html
# |----------------------------------------------------------------
# | ADAPTED FROM: Andrew D. Martin. "Bayesian Inference and Computation in Political Science." Slides from a talk given to the Department of Politics, Nuffield College, Oxford University, March 9, # | 2004. SLIDES:http://adm.wustl.edu/media/talks/bayesslides.pdf R-CODE : http://adm.wustl.edu/media/talks/examples.zip
# |
# |
# |
@BioSciEconomist
BioSciEconomist / ex qtl.r
Created November 5, 2016 22:05
QTL Analysis in R
# ------------------------------------------------------------------
# |PROGRAM NAME: EX_QTL_R
# |DATE: 8-13-11
# |CREATED BY: MATT BOGARD
# |PROJECT FILE: http://econometricsense.blogspot.com/2011/08/qtl-analysis-in-r.html
# |----------------------------------------------------------------
# | PURPOSE: DEMONSTRATE STATISTICAL METHODS FOR QTL ANALYSIS IN R
# |
# |------------------------------------------------------------------
# | REFERENCE: R code for "A brief tour of R/qtl"
@BioSciEconomist
BioSciEconomist / roc demo.r
Created November 6, 2016 02:24
An intuitive approach to ROC curves
# R Code to support: http://econometricsense.blogspot.com/2011/05/intuitive-approach-to-roc-curves-with.html
# *------------------------------------------------------------------
# |
# | import scored logit data from SAS - code generated by SAS MACRO %EXPORT_TO_R
# |
# |
# *-----------------------------------------------------------------
@BioSciEconomist
BioSciEconomist / indifference curves.r
Created November 6, 2016 12:56
Plotting Indifference Curves or Level Sets in R
# *------------------------------------------------------------------
# | PROGRAM NAME: INDIFFERENCE_CURVES_R
# | DATE: 3/11/11
# | CREATED BY: MATT BOGARD
# | PROJECT FILE: http://econometricsense.blogspot.com/2011/03/plotting-indifference-curves-with-r.html
# *----------------------------------------------------------------
# | PURPOSE: MORE TO PLOT LEVEL SETS USING THE CONTOUR FUNCTION THAN
# | TO ACTUALLY PLOT INDIFFERENCE CURVES
# *------------------------------------------------------------------
# | COMMENTS:
@BioSciEconomist
BioSciEconomist / r copula graphs.r
Created November 6, 2016 17:10
Copula functions, R, and the financial crisis
# *------------------------------------------------------------------
# | PROGRAM NAME: R_COPULA_BASIC
# | DATE: 1/25/11
# | CREATED BY: Matt Bogard
# | PROJECT FILE: http://econometricsense.blogspot.com/2011/03/copula-functions-r-and-financial-crisis.html
# *----------------------------------------------------------------
# | PURPOSE: copula graphics
# |
# *------------------------------------------------------------------
# | COMMENTS:
@BioSciEconomist
BioSciEconomist / mutli merge.r
Created November 6, 2016 17:13
Merging multiple date frames in R
### r code to support: http://econometricsense.blogspot.com/2011/01/merging-multiple-data-frames-in-r.html
# read all Y2000 csv files
filenames <- list.files(path="/Users/wkuuser/Desktop/R Data Sets/TRADE_DATA/TempData00", full.names=TRUE)
import.list <- llply(filenames, read.csv)
# left join all Y2000 csv files
AllData00 <- Reduce(function(x, y) merge(x, y, all=FALSE,by.x="Reporting.Countries.Partner.Countries",by.y="Reporting.Countries.Partner.Countries",all.x =TRUE, all.y =FALSE),import.list,accumulate=F)
@BioSciEconomist
BioSciEconomist / density plots.r
Last active November 6, 2016 17:19
Overlapping density plots
### r code to support: http://econometricsense.blogspot.com/2011/01/flexibility-of-r-graphics.html
library(colorspace) # package for rainbow_hcl function
ds <- rbind(data.frame(dat=KyCropsAndSubsidies[,][,"LogAcres"], grp="All"),
data.frame(dat=KyCropsAndSubsidies[,][KyCropsAndSubsidies$subsidy_in_millions > 2.76,"LogAcres"], grp=">median"),
data.frame(dat=KyCropsAndSubsidies[,][KyCropsAndSubsidies$subsidy_in_millions <= 2.76,"LogAcres"], grp="<=median"))