Skip to content

Instantly share code, notes, and snippets.

@comicalequation
comicalequation / simulation.R
Last active January 21, 2019 06:24
Simulating a sample of fixed size from a population of unknown size in R to compare mean and ratio estimators
library(MASS)
Ybar=72
yrvec<-c()
ratvec<-c()
for(i in 1:500)
{
df<-data.frame(mvrnorm(n=50,mu=c(60,71),Sigma=matrix(c(186,142,142,117),2,2),empirical=TRUE))
xnbar<-mean(df[,1])
a<-sample.int(50,10)
df=df[-a,]
@comicalequation
comicalequation / ratvsmean.R
Last active January 18, 2019 05:55
A R script to select all possible samples of size n from a population of size N and find the relative efficiency of mean and ratio methods of imputation
library(combinat)
library(readxl)
bookdata <- read_excel("Math notemos/Rstudio/bookdata.xlsx",
+ col_names = FALSE)
data<-data.frame(matrix(unlist(bookdata),nrow=9,byrow=F))
combinations <- combn(nrow(data), 3, function(x,data) data[x,],
simplify = FALSE, data =data)
Ybar<-mean(data[,2])
n1<-ncol(combn(nrow(data),3))
yrvec<-c()
@comicalequation
comicalequation / sample1.R
Last active November 28, 2017 19:04
A simple R script to draw a sample from given bivariate discrete data
#we use in-built data-set faithful for this example
s<-sample(1:nrow(faithful),30)
sampled.x<-faithful$eruptions[s]
sampled.y<-faithful$waiting[s]
sample<-cbind(sampled.x,sampled.y)
sample
@comicalequation
comicalequation / simulestimator.r
Created November 4, 2017 07:50
A R script for simulating data for 100 trials and finding estimations, bias and MSE of dual to ratio, compromised, Walsh, exponential estimators, and comparing it with sample mean and ratio estimators
#generating population data
library(MASS)
data1<-data.frame(mvrnorm(n=10,mu=c(20,25),
Sigma=matrix(c(1,0.94,0.94,1),2,2),empirical=TRUE))
colnames(data1)=c("X","Y")
scatter.smooth(data1$X,data1$Y, xlab="X", ylab="Y",main="X vs Y graph")
#finding population values
pmeans<-colMeans(data1)
Xbar<-pmeans[1]
@comicalequation
comicalequation / dualtoratio.R
Created October 31, 2017 10:00
A R script for simulating 100 trials and studying dual to ratio estimator and its properties
library(MASS)
data1<-data.frame(mvrnorm(n=10,mu=c(20,25),Sigma=matrix(c(2.5,0.94,0.94,2.3),2,2),empirical=TRUE))
colnames(data1)=c("X","Y")
pmeans<-colMeans(data1)
Xbar<-pmeans[1]
Ybar<-pmeans[2]
xvec<-c()
yvec<-c()
xstarvec<-c()
ydrvec<-c()
@comicalequation
comicalequation / pert.c
Created October 14, 2017 10:34
A C program for project scheduling using PERT
#include<stdio.h>
#include<math.h>
int main()
{
int n,i,j,k,m=65,to[15],tp[15],tm[15],ver,sn[15],en[15],task[20][20], a[20][20],fp[15],bp[15],ca[15],nca,ef[15],lf[15];
char tname[20];
float te[15],pv=0.0,psd,u,v[15],ct,gt,zo,gp,prob;
printf("\nEnter no. of tasks: ");
scanf("%d",&n);
printf("\nEnter optimistic time, pessimistic time and most likely time for each task:\n");
@comicalequation
comicalequation / lahiriwor.c
Created September 28, 2017 13:06
A C program implementation of selecting a PPSWOR sample using Lahiri Method
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,x[100],a[100],m,N,n,u,v;
printf("\nEnter the number of units in population: ");
scanf("%d",&N);
printf("\nEnter the number of units to be selected in the sample: ");
scanf("%d",&n);
printf("\nEnter the sizes of units: ");
@comicalequation
comicalequation / lahiriwr.c
Created September 28, 2017 13:05
A C program implementation of selecting a PPSWR sample using Lahiri Method
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,x[100],m,N,n,u,v;
printf("\nEnter the number of units in population: ");
scanf("%d",&N);
printf("\nEnter the number of units to be selected in the sample: ");
scanf("%d",&n);
printf("\nEnter the sizes of units: ");
@comicalequation
comicalequation / ctmwor.c
Created September 28, 2017 13:04
A C program implementation of selecting a PPSWOR sample using Cumulative Total Method
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,x[100],c[100],a[100],X=0,N,n,r;
printf("\nEnter the number of units in population: ");
scanf("%d",&N);
printf("\nEnter the number of units to be selected in the sample: ");
scanf("%d",&n);
printf("\nEnter the sizes of units: ");
@comicalequation
comicalequation / ctmwr.c
Created September 28, 2017 13:03
A C program implementation of selecting a PPSWR sample using Cumulative Total Method
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,x[100],c[100],X=0,N,n,r;
printf("\nEnter the number of units in population: ");
scanf("%d",&N);
printf("\nEnter the number of units to be selected in the sample: ");
scanf("%d",&n);
printf("\nEnter the sizes of units: ");