楼主: leoking08
1103 1

[问答] 新手求助一些R的问题 [推广有奖]

  • 0关注
  • 0粉丝

学前班

80%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
30 点
帖子
1
精华
0
在线时间
4 小时
注册时间
2015-1-21
最后登录
2018-10-22

楼主
leoking08 发表于 2015-2-25 08:02:51 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
新手最近刚在学习使用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.
二维码

扫码加我 拉你入群

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

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

关键词:新手求助 Astronomical distribution Probability significant function against testing numbers without

沙发
Ipomy 发表于 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] # 输出



您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 11:27