Skip to content

Instantly share code, notes, and snippets.

@leoschet
Last active August 29, 2015 14:04
Show Gist options
  • Save leoschet/62627fb719156f06ab4d to your computer and use it in GitHub Desktop.
Save leoschet/62627fb719156f06ab4d to your computer and use it in GitHub Desktop.
R code
# author: ljsa @ cin.ufpe.br
# two decimal places
decimal = function (number){
return(format(round(number, 2), nsmall = 2));
}
# cast function
character = function (text){
return(as.character(decimal(text)));
}
# library for function plot
# entries = population vector
# sample = sample vector
# type = bilateral, unilateral a direita (rigth), unilateral a esquerda (left)
# confidenceRate = confidence rate (0~1)
library('visualizationTools');
testeHipotese = function (entries, sample, type, confidenceRate){
mean = mean(entries);
if(type == "bilateral") {
alt = "two.sided";
str = paste("H0: u = ", as.character(decimal(mean)));
print(str);
str = paste("Ha: u != ", as.character(decimal(mean)));
print(str);
} else if (type == "unilateral a direita"){
alt = "greater";
str = paste("H0: u <= ", as.character(decimal(mean)));
print(str);
str = paste("Ha: u > ", as.character(decimal(mean)));
print(str);
} else if (type == "unilateral a esquerda"){
alt = "less";
str = paste("H0: u >= ", as.character(decimal(mean)));
print(str);
str = paste("Ha: u < ", as.character(decimal(mean)));
print(str);
} else {
return(null);
}
# Realiza o teste
test = t.test(x = sample, alternative = alt, conf.level = confidenceRate, mu = mean);
plot(test);
print(test);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment