Skip to content

Instantly share code, notes, and snippets.

View viniciusmss's full-sized avatar

Vinícius Miranda viniciusmss

  • Facebook
  • San Francisco
View GitHub Profile
@viniciusmss
viniciusmss / k-way merge sort.py
Created January 25, 2018 09:28
CS110 - Assignment 1
def merge(arr, l, mids, r):
'''
Merge is a subprocedure of mergeSort, declared below. It
merges k sorted subarrays into a sorted array. It does so by
iterating continuously over all subarrays, finding the smallest key,
and relocating it to the right position of the outcome array.
Inputs:
arr (list) The entire array to be sorted.
@viniciusmss
viniciusmss / Traffic Flow.py
Created February 16, 2018 12:56
Replication code for the Traffic Simulation Assignment.
import pylab as py
import scipy
import random
import matplotlib
from matplotlib import pyplot as plt
%matplotlib inline
class TrafficSimulation:
def __init__(self, road_length=100, traffic_density=0.1, maximum_velocity=5,
set.seed(2626)
# Create toy dataset
x1 <- rnorm(200, mean = 10, sd =2)
x2 <- rnorm(200, mean = 50, sd =7)
y <- 10 + 4*x1 + 0.5*x2 - 0.1*x1*x2 + rnorm(200, mean = 0, sd = 5)
data <- data.frame(x1, x2, y)
# Spliting the data
# Cleaning the workspace
rm(list = ls())
# Loading the data
library(Matching)
data(lalonde)
View(lalonde)
str(lalonde)
# Let's look at two individuals. For the purposes of this tutorial,
# Importing the data
# I'm just importing the dataset after having transformed the data columns to numeric.
df <- read.csv("C:/Users/Vinic/Downloads/Copy of datasetforCS112 - TA.csv",
stringsAsFactors = F)
str(df)
# Converting char columns to numeric
df$cumulative.disbursements <-
as.numeric(df$cumulative.disbursements)
df$undisbursed.amount <-
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Characteristics of the data set to be generated:
#
# N(mu, sigma) error term,
# 500 treated units, 500 control units,
# Predictors: treatment (binary variable), and
# hectares (continuous variable--use a uniform distribution),
# pre-treatment productivity (continuous variable--use a uniform distribution).
# Outcome variable: post-treatment productivity: (continuous variable).
set.seed(1234)
##############
# QUESTION 1 #
##############
# Generating 99 observations
library(haven)
df <- read_dta("C:/Users/Vinic/Downloads/turnout.dta")
View(df)
df[1,1]
df[1,]
lm2 <- glm(turnout ~ ., data = df, family = binomial)
summary(lm2)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.