全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1064 1
2015-02-25
新手最近刚在学习使用Rstudio,有些问题问下坛里的大大。1. Using R, write a program to calculate all the prime numbers less than 100. A prime number is a positiveinteger divisible (without remainder) only by 1 and itself. Create the program by testing each numberfrom 1 to 100 against all integers less than it using %%. Your function should return a vector of all theprimes < 100.

2. Using R, create a histogram of the result from 1 using ggplot. Be sure to nicely label your axes andtitle the graph.

3. You flip a coin five times.
a. What’s the chance of getting three or more heads in a row?
b. What’s the chance of getting three or more heads in a row conditional on knowing the first flip was aheads?

4. NASA has declared that the Earth is likely to be hit by an asteroid this year based on an astronomicalobservation it has made. These things are hard to judge for certain, but it is known that the test NASAused is pretty good – it has an accuracy (sensitivity) of 99% and a false positive rate of only 1%. It isfurther known that the general probability of an asteroid hitting earth in any given year is 1 in 100,000.What is the probability we will actually be hit by an asteroid this year given NASA’s test?

5. The average number of snow days in Beijing in a winter month is 1. Assuming these events follow apoisson distribution, what is the probability of getting 5 or more snow days in a month?

6. You want to know how many hours of sleep the average college student gets. You start out witha preliminary survey of 10 people, and get the following data (in hours): 7,6,5,8,6,6,4,5,8,7. Youhypothesize that despite what the doctors say, the average college student does not get 7 hours of sleepa night. What does your survey say? State your null hypothesis, research hypothesis (two tailed), andcalculate your threshold value, test statistic, and p value. Do you reject the null or not?  

7. Despite the disappointing results in 6, you are confident in your hypothesis. Assuming your samplestandard deviation and mean do not change and you want to survey as few people as possible, howmany additional people would you have to survey to reject the null at the 0.05 level?


8. You survey the same 10 people during finals period, and get the following hours: 5,4,5,7,5,4,5,4,6,5 .Do people get significantly less sleep during finals?


9. You are a very bad gardener, and hypothesize that feeding houseplants vodka might help them relaxand grow better. You perform an experiment to test your hypothesis, giving 15 houseplants waterspiked with vodka, and 15 houseplants water alone. These are your results:condition   live   die
                                  treatment   4     11
                                  control       8      7
This looks pretty bad for the treatment, but being as good at statistics as you are bad at gardening,1you test it using the chi-square test. What are your results?


10. Perhaps you got things backwards, and plants need more stimulation to thrive. So you adjust yourexperiment into three treatment groups: water, vodka, and coffee.
These are your results: condition   mean-days-alive    sd    n
                                  water                 50              10   20
                                  vodka                 45               7   10
                                  coffee                 55              4    10
The overall mean is 50 days (as we said, you’re a bad gardener). Use an F test to determine ifthere is any significant difference among these three groups.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-2-26 09:39:00
都不难,给你贴下第一题的代码好了

首先写一个判断素数的函数
isprime <- function(x)  # TRUE x是素数  FALSE x 不是素数
{
      if (x < 4)  # 2、3特判一下
             return(TRUE)
      !any(x %% 2:floor(sqrt(x)) == 0)  # 把x从2到[sqrt(x)]皆试除一遍,只要有一个能整除x,就说明x不是素数
}

primes <- rep(FALSE, 99)  # 布尔向量,primes[i]为TRUE,代表i为素数
for (i in 2:99) # 逐个扫描
     if (isprime(i))
          primes[i] <- TRUE
(1:99)[primes] # 输出



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群