Stats 102A HW4

Stats 102A HW4 Due March 3, 2020
General Notes
• You will submit a minimum of three files, the core files must conform to the following
naming conventions (including capitalization and underscores). 123456789 is a placeholder,
please replace these nine digits with your nine-digit Bruin ID. The files you must submit are:
1. 123456789_stats102a_hw1.R: An R script file containing all of the functions you wrote
for the homework. The first line of your .Rmd file, after loading libraries, should be
sourcing this script file.
2. 123456789_stats102a_hw1.Rmd: Your markdown file which generates the output file
of your submission.
3. 123456789_stats102a_hw1.html/pdf : Your output file, either a PDF or an HTML file
depending on the output you choose to generate.
4. included image files: You may name these what you choose, but you must include all of
the image files you generated for your structured flowcharts, otherwise your file will not
knit.
If you fail to submit any of the required core files you will receive ZERO points for the
assignment. If you submit any files which do not conform to the specified naming
convention, you will receive (at most) half credit for the assignment.
• Your .Rmd file must knit. If your .Rmd file does not knit you will receive (at most) half
credit for the assignment.
The two most common reason files fail to knit are because of workspace/directory structure
Stats 102A作业代做、代写R程序语言作业x
issues and because of missing include files. To remedy the first, ensure all of the file paths in
your document are relative paths pointing at the current working directory. To remedy the
second, simply make sure you upload any and all files you source or include in your .Rmd
file.
• Your coding should adhere to the tidyverse style guide: https://style.tidyverse.org/.
• All flowcharts should be done on separate sheets of paper, but be included, inline as images,
in your final markdown document.
• Any functions/classes you write should have the corresponding comments as the following
format.
my_function <- function(x, y, ...){
#A short description of the function
#Args:
#x: Variable type and dimension
#y: Variable type and dimension
#Return:
#Variable type and dimension
Your codes begin here
}
1
Stats 102A HW4 Due March 3, 2020
NOTE: Everything you need to do this assignment is here, in your class notes, or was covered in
discussion or lecture.
• DO NOT look for solutions online.
• DO NOT collaborate with anyone inside (or outside) of this class.
• Work INDEPENDENTLY on this assignment.
• EVERYTHING you submit MUST be 100% your, original, work product. Any student
suspected of plagiarizing, in whole or in part, any portion of this assignment, will be
immediately referred to the Dean of Student’s office without warning.
1: Dealing with Large Numbers
To calculate with large floating point numbers we define objects called (p, q) number with a list as
its base type. The list should have four components. The first one is either the integer +1 or the
integer −1. It gives the sign of the number. The second and third are p and q. And the fourth
component is a vector of p + q + 1 integers between zero and nine. For example,
x <- structure(list(sign = 1, p = 3, q = 4, nums = 1:8), class = "pqnumber")
(a) Write a constructor function, an appropriate predicate function, appropriate coercion
functions, and a useful print() method.
• The constructor takes the four arguments: sign, p, q, and nums. Then check if the
arguments satisfy all requirements for a (p, q) number. If not, stop with an error
message. If yes, return a (p, q) number object.
• A predicate is a function that returns a single TRUE or FALSE, like is.character(), or
is.NULL(). Your predicate function should be is_pqnumber() and should behave as
expected.
• A useful print() method should allow users to print a (p, q) number object with the
decimal representation defined as follows:
x =
X
q
s=−p
xs × 10s
Thus p = 3 and q = 4 with nums = 1:8 has the decimal value
0.001 + 0.002 + 0.3 + 4 + 50 + 600 + 7000 + 80000 = 87654.321
• A coercion function forces an object to belong to a class, such as as.character() or
as_tibble(). You will create a generic coercion function as_pqnumber() which will
accept a numeric or integer argument x and return the appropriate (p, q) number object.
For example, given the decimal number 3.14 with p = 3 and q = 4, the function will
return a (p, q) number with num = c(0, 4, 1, 3, 0, 0, 0, 0). You should also create a
generic as_numeric() function and a method to handle a (p, q) number.
2
Stats 102A HW4 Due March 3, 2020
(b) Write an addition function and a subtraction function
Suppose we have two positive (p, q) number objects x and y. Write a function to calculate the
sum of x and y. Clearly its decimal representation is
x + y =
X
q
s=−p
(xs + ys) × 10s
but this cannot be used directly because we can have xs + ys > 9.
So we need a carry-over algorithm that moves the extra digits in the appropriate way. Same
as one would do when adding two large numbers on paper. Also we need a special provision
for overflow, because the sum of two (p, q) number objects can be too big to be a (p, q)
number.
A subtraction algorithm should have a carry-over algorithm that borrows 10 in the same way
as you would do a subtraction with pencil-and-paper.
Your functions should work for both positive and negative (p, q) numbers.
(c) Write a multiplication function Write a function which can multiply two pqnumber objects.
Think about how you would multiply two large numbers by hand and implement that
algorithm in R for two pqnumber objects.
2: Statistical Computing
Skewness and Kurtosis:
For a vector of values x = (x1, x2, ..., xn), the kth sample moment of x around c is defined as.
The first (k = 1) sample moment around c = 0 is called the sample mean x¯ =
1ni=1 xi.
A sample moment is called central if it is a moment around the mean, i.e., c = ¯x. That is, the
kth sample central moment of x is
The skewness of x is defined as
γ1 =µ3(µ2)3/2,
and the kurtosis of x is defined as
γ2 =µ4µ22− 3,
where muk is the kth central moment of x.
Suppose we have a vector of numbers x.
(a) Write a function to compute the sample moments of x around 0 for k = 1, 2, 3, 4.
3
Stats 102A HW4 Due March 3, 2020
(b) Write a function to compute the sample central moments of x for k = 1, 2, 3, 4.
(c) Write a function to compute the skewness and kurtosis of x.
For each question, the function should take the vector x as an argument and return a list or
vector of results. The functions can call each other if that seems desirable. Try to avoid loops. Do
not use built-in function such as mean() or var(), except possibly for checking your results. You
may use the sum() function.
For each function you need to test that it works by applying it to randomly generated numbers.
Specifically, use at least 4 different built-in R functions for generating random numbers (use
?Distributions for a list of possible functions to use) to generate random vectors (of at least
length 1,000) to try out your code. Generate a table with skewness and kurtosis results for the
four distributions you chose. Do not print a table directly from R; collect the results that are
needed and then put them in a Markdown table.
如有需要,请加QQ:99515681 或邮箱:[email protected] 微信:codehelp

原文地址:https://www.cnblogs.com/welcomeyou/p/12444159.html

时间: 2024-10-31 14:45:09

Stats 102A HW4的相关文章

stats.js随时查看fps

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta h

android battery stats

battery stats android 5.1.0-2.0.0 ./frameworks/base/services/jni/com_android_server_BatteryService.cpp android 5.1.0-2.1.0 system/core/healthd

Memcahce(MC)系列(七)Memcached stats命令

Memcached stats命令,对于查看Memcache运行状态来说,是非常有用的. telnet到memcached服务器后有很多的命令可以使用,除了大家熟知的add.get.set.incr.decr.replace.delete等赋值命令外,还有一系列的获取服务器信息的命令,这部分命令都是以stats开头的. 常用的命令: stats显示服务器信息.统计数据等 stats reset清空统计数据 stats cachedump  slab_id  limit_num显示某个slab中的

关于OGG stats 命令的解释

GGSCI (gg321) 19> stats extqd Sending STATS request to EXTRACT EXTQD ... Start of Statistics at 2015-04-18 17:53:06. Output to /u02/ggs/dirdat/qd: Extracting from usera.taba to usea.taba: *** Total statistics since 2015-04-18 17:38:42 *** Total inser

关于OGG的stats 进程名 reset命令

Oracle GoldenGate Command Interpreter for Oracle Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100 Linux, x86, 32bit (optimized), Oracle 10g on Oct 4 2011 23:54:04 Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.

apache hive 无法收集stats问题

环境: hive: apache-hive-1.1.0 hadoop:hadoop-2.5.0-cdh5.3.2 hive元数据以及stats使用mysql进行存储. hive stats相关参数如下: hive.stats.autogather:在insert overwrite命令时自动收集统计信息,默认开启true:设置为true hive.stats.dbclass:存储hive临时统计信息的数据库,默认是jdbc:derby:设置为jdbc:mysql hive.stats.jdbcd

unity---gameScreen 的Stats参数

Unity Stats 面板介绍 原创 2016年06月12日 10:06:12 1544 0 3 Time per frame and FPS (每帧的时间和FPS):处理和渲染一个游戏框架(以及由此产生的FPS)的需要多少时间.请注意,这个数量只包括游戏视图更新和渲染的帧,不包括在编辑器中绘制场景视图,检视窗口和其他仅编辑器进程的时间. Draw Calls(描绘调用):批处理后网格绘制的总数.请注意其中有对象被多次渲染(例如,被像素灯光照亮的物体),每次渲染结果都会导致一个单独的描绘调用.

Memcached 查询stats及各项状态解释

一.两个最常用状态查询(掌握第一个就完全OK了) 1)查看状态:printf “stats\r\n” |nc 127.0.0.1 11211      2)模拟top命令查看状态:watch “echo stats” |nc 127.0.0.1 11211 二.各种stats中文解释.但工作中最常关注的只有四个. STAT get_hits 1(序号,并不是结果,如下)       STAT get_misses 2       STAT curr_items 3       STAT tota

[转] MemCached 的 stats 命令

Memcached有个stats命令,通过它可以查看Memcached服务的许多状态信息.使用方法如下:先在命令行直接输入telnet 主机名端口号,连接到memcached服务器,然后再连接成功后,输入stats 命令,即可显示当前memcached服务的状态信息.比如在我本机测试如下: stats STAT pid 1552 STAT uptime 3792 STAT time 1262517674 STAT version 1.2.6 STAT pointer_size 32 STAT c