Last active
August 29, 2015 14:04
-
-
Save leoschet/62627fb719156f06ab4d to your computer and use it in GitHub Desktop.
R code
This file contains hidden or 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
# 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