Skip to content

Instantly share code, notes, and snippets.

View fawda123's full-sized avatar

Marcus W Beck fawda123

View GitHub Profile
#install the packages
install.packages('XML')
require(XML)
#get raw html for Lake Minnetonka
html.raw<-htmlTreeParse(
'http://www.dnr.state.mn.us/lakefind/showreport.html?downum=27013300',
useInternalNodes=T
)
#import relevant packages
library(gstat)
library(sp)
library(nlme)
#create simulated data, lat and lon from uniformly distributed variable, exp1 and exp2 from random normal
set.seed(2)
samp.sz<-400
lat<-runif(samp.sz,-4,4)
lon<-runif(samp.sz,-4,4)
catch.fun<-function(dows,fish.str,net.type='Trap',trace=T,clean=F){
require(XML)
strt<-Sys.time()
#create object for output
fish.out<-data.frame(expand.grid(dows,fish.str),NA,NA)
names(fish.out)<-c('dows','fish','fish.val','result')
vif_func<-function(in_frame,thresh=10,trace=T,...){
library(fmsb)
if(any(!'data.frame' %in% class(in_frame))) in_frame<-data.frame(in_frame)
#get initial vif value for all comparisons of variables
vif_init<-NULL
var_names <- names(in_frame)
for(val in var_names){
@fawda123
fawda123 / catch_fun_v2.r
Last active December 13, 2015 21:38
catch_fun_v2
catch.fun.v2<-function(dows,trace=T,rich.out=F){
require(XML)
strt<-Sys.time()
#create object for output
fish.out<-vector('list',length(dows))
names(fish.out)<-dows
@fawda123
fawda123 / nnet_plot_fun.r
Last active December 14, 2015 12:29
nnet_plot_fun
plot.nnet<-function(mod.in,nid=T,all.out=T,all.in=T,wts.only=F,rel.rsc=5,circle.cex=5,node.labs=T,
line.stag=NULL,cex.val=1,alpha.val=1,circle.col='lightgrey',pos.col='black',neg.col='grey',...){
require(scales)
#gets weights for neural network, output is list
#if rescaled argument is true, weights are returned but rescaled based on abs value
nnet.vals<-function(mod.in,nid,rel.rsc){
library(scales)
@fawda123
fawda123 / server.R
Last active December 14, 2015 22:20
shinyServer(function(input, output) {
myData <- reactive({
read.csv(input$file$datapath)
})
output$summary <- renderPrint({
if (is.null(input$file)) {
return(cat('File not uploaded'))
@fawda123
fawda123 / loess_fitting.r
Last active December 14, 2015 23:29
loess_fitting
obs<-100
x<-runif(obs,0,100)
y<-x^2+rnorm(obs,0,800)
require(scales)
#examples with span
par(mfrow=c(2,2),mar=c(4,4,0.5,0.5),family='serif')
span<-round(seq(0.5,0.1,length=4),2)
for(i in span){
@fawda123
fawda123 / plot_qual.r
Last active October 24, 2016 14:04
plot_qual
plot.qual<-function(x,x.locs=c(0.01,0.99),y.locs=c(0,1),steps=NULL,sp.names=NULL,dt.tx=T,rsc=T,
ln.st=NULL,rs.ln=c(3,15),ln.cl='RdYlGn',alpha=0.7,leg=T,rnks=FALSE,...){
require(RColorBrewer)
require(scales)
if(length(x.locs) != 2 | length(y.locs) != 2)
stop('x and y dimensions must be two-element vectors')
if(x.locs[1]<0 | x.locs[2]>1 | y.locs[1]<0 | y.locs[2]>1)
@fawda123
fawda123 / mc_int.r
Created April 29, 2013 18:54
mc_int
mc.int<-function(mod.in,int=NULL,n=10000,int.base=0,plot=T,plot.pts=T,
plot.poly=T,cols=list('black','green','blue'),round.val=2,val=F){
require(scales)
#variable names from model
if(is.null(mod.in$call$formula)){
x.names<-colnames(eval(mod.in$call$x))
y.names<-colnames(eval(mod.in$call$y))
x.range<-range(eval(mod.in$call$x))