Instantly share code, notes, and snippets.

# Giulio Valentino Dalla Riva gvdr

• School of Mathematics and Statistics, University of Canterbury
• Christchurch, New Zealand
Created April 22, 2015 21:59
Compute the ordinary Procrustes sum of squares of two matrices in Julialang. All credits to procOPA {shapes}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #This is just a quick translation of an ordinary Procrustes sum of squares method, as done in the R function procOPA. #All credits to Dryden, I. L. (2014). shapes package. R Foundation for Statistical Computing, Vienna, Austria. Contributed package. Version 1-1.10. URL http://www.R-project.org #The function are, for now, as they are. I'll be working on them in the future... #Compute a matrix with ones on the main diagonal #and -1/n elsewhere function scaled_ones(n) eye(n) - (1/n) * ones(n,n) end
Last active December 19, 2015 02:18
A Markovian trait based fields of bullets method. Based on dendropy and random, mfob is a small module that permits a fast implementation of a fields of bullets model where the probability of extinction depends on a binary trait evolved from the root as a markov process.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Created on Fri Jun 21 10:52:11 2013 @author: Giulio Valentino Dalla Riva @email: gvd16@uclive.ac.nz """ #generate a tree list following a birth and death process #the process is conditioned to N leaves (with success) #the list is long rang def generate_trees_bdN(birth=0.57721,death=0.130357,N=49,rang=314):
Created July 1, 2016 02:03
How to handle a matrix in a dataframe. How I do it?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #' let's have a matrix n <- 2 m <- 15 my_mat <- matrix(runif(n),m,n) #' let's name those rows, they will be our observations row.names(my_mat) <- letters[1:m]
Created October 25, 2017 17:54
How to group by numeric variables in a dataframe and compute percentiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # install.packages("tidyverse") # If not yet installed, run this library(tidyverse) # Everything will be don in a tidyverse fashion # This is the kind of dataframe I think Roberta is dealing with. # Vitd is an integer # Age is a numeric # We first need to cut the numeric age into a factor. roberta_df <- tibble( Age = as.integer(runif(100,10,100)), # Age, as an integer Vitd = as.integer(runif(100,80,140)) # Vitd, as an integer
Created July 18, 2018 23:15
installation notes for DATA201 and DATA422
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 Data Wrangling Stack -------------------- In this course we will use: - R as default programming language - Tidyverse as the R dialect of choice - The shell commands (bash or zsh), through the terminal
Last active October 25, 2018 07:22
A quick exploratory analysis of the dataset collected by BEtti and Manica (Betti L, Manica A (2018) Human variation in the shape of the birth canal is significant and geographically structured. Proceedings of the Royal Society B 285(1889)

# Diversity in Birth Canal across the world

A quick exploratory analysis of the dataset collected by BEtti and Manica (Betti L, Manica A (2018) Human variation in the shape of the birth canal is significant and geographically structured. Proceedings of the Royal Society B 285(1889): 20181807.)

We perform classic multidimensional scaling and contrast it with the aggregate means by Region and Population.

Let's load the tidyverse framework to wrangle data and plot it

Created April 12, 2019 00:57

### Keybase proof

I hereby claim:

• I am gvdr on github.
• I am gvdr (https://keybase.io/gvdr) on keybase.
• I have a public key ASBW8zEL_gVtBeSjRwk9_S8_4Xi1x1vlzFwdUc0JDHZDSwo

To claim this, I am signing this object:

Created January 11, 2020 08:09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 using StatsBase, Random, Distributions using Plots # parameters for the simulations blocks = 70000; # Number of ticket blocks tickets = 7000000; # Number of tickets draws = 200; # Number of prizes K = 100000; # Number of lotteries to simulate at each replication R = 100; # Number of replications
Created February 25, 2020 01:03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # I'd live to use the usual mathematical notations to do summatories and productories # turns out, in Julia it's pretty easy as long as we keep things simple # as we can just embellish the already defined sum() and prod() function # only tweak is choosing a negative step if we want to sum from i = N to M with N>M # for the summatory: function ∑(f::T;from::Int, to::Int) where T <: Function step_sum = from > to ? 1 : -1 sum(safer(f), range(from, stop = to, step = step_sum)) end
Created April 2, 2020 03:48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters