指数曲线拟合R中的直方图

时间:2018-03-24 16:21:33

标签: r histogram curve

我在R中制作了一个直方图,我必须在其上插入指数曲线。

enter image description here

但曲线没有出现在直方图上。

这是代码:

hist(Adat$price, main="histogram",xlab="data")
curve(dexp(x, rate=1,log=FALSE), add = TRUE)

有人能帮帮我吗?

1 个答案:

答案 0 :(得分:1)

如果要对直方图进行规范化,则需要添加设置参数 .data var_i: .word 0 var_j: .word 0 var_k: .word 0 var_num: .space 4 msg_pedirNumeroFilas: .asciiz "Input number of rows: " msg_espacioCorto: .asciiz " " msg_espacioLargo: .asciiz " " msg_saltoDeLinea: .asciiz "\n" .text # Función principal del programa MAIN: # Show message "InputNumRows" la $a0, msg_pedirNumeroFilas li $v0, 4 syscall # Get number of rows li $v0, 5 syscall # Save in memory this number of rows sw $v0, var_num # Store in saved var our program variables lw $s0, var_i # Save in $s0 var_i lw $s1, var_j # Save in $s1 var_j lw $s2, var_k # Save in $s2 var_k lw $s3, var_num # Save in $s2 var_num # Save in stack i, j, k, num addi $sp, $sp, -16 sw $s0, 0($sp) sw $s1, 4($sp) sw $s2, 8($sp) sw $s3, 12($sp) # for (i = 0; i < num; i++) li $s0, 0 # i = 0 FOR_I: bge $s0, $s3, END_FOR_I # (i >= num) ? GOTO END_FOR_I : CONTINUE # for (j = num; j > i; j--) { move $s1, $s3 # j = num FOR_J: ble $s1, $s0, END_FOR_J # (j <= i) ? GOTO END_FOR_J : CONTINUE # Print spaces la $a0, msg_espacioCorto li $v0, 4 syscall addi $s1, $s1, -1 # j -= 1 j FOR_J # GOTO FOR_J END_FOR_J: # for (k = 0; k <= i; k++) { li $s2, 0 # k = 0 FOR_K: bgt $s2, $s0, END_FOR_K # (k > i) ? GOTO END_FOR_K : CONTINUE # Print spaces la $a0, msg_espacioLargo li $v0, 4 syscall # Llamada a la función recursiva move $a0, $s0 # Pass as first argument i move $a1, $s2 # Pass as second argument k jal TRIANGULO_PASCAL # Call to triangulo_pascal(i, k) # Print returned result move $a0, $v0 li $v0, 1 syscall addi $s2, $s2, 1 # k += 1 j FOR_K # GOTO FOR_K END_FOR_K: # Print \n la $a0, msg_saltoDeLinea li $v0, 4 syscall addi $s0, $s0, 1 # i += 1 j FOR_I # GOTO FOR_I END_FOR_I: # Load from stack i, j, k, num lw $s0, 0($sp) lw $s1, 4($sp) lw $s2, 8($sp) lw $s3, 12($sp) addi $sp, $sp, 16 EXIT: # Exit program li $v0, 10 syscall END_EXIT: END_MAIN: # Pascal triangle function TRIANGULO_PASCAL: # Save in stack addi $sp, $sp, -20 sw $ra, 0($sp) # Save StackPointer sw $s0, 4($sp) # Save i sw $s1, 8($sp) # Save j sw $s2, 12($sp) # Save returned value of trianguloPascal(i-1, k-1) sw $s3, 16($sp) # ave returned value of trianguloPascal(i-1, k) move $s0, $a0 # $s0 = i actual ((i-1), ((i-1)-1), ...) move $s1, $a1 # $s1 = k actual ((k-1), ((k-1)-1), k, ...) IF: # ((i == 0) || (k == 0) || (i == k)) ? GOTO ELSE : CONTINUE beq $s0, 0, RETURN_1 # (i == 0) ? GOTO RETURN_1 : CONTINUE beq $s1, 0, RETURN_1 # (k == 0) ? GOTO RETURN_1 : CONTINUE bne $s0, $s1, ELSE # (i != k) ? GOTO ELSE : CONTINUE RETURN_1: li $v0, 1 # return (1) j END_TRIANGULO_PASCAL # GOTO END_TRIANGULO_PASCAL END_RETURN_1: ELSE: addi $a0, $s0, -1 # i-1 addi $a1, $s1, -1 # k-1 jal TRIANGULO_PASCAL # Call to trianguloPascal(i-1, k-1) add $s2, $zero, $v0 # $s2 = trianguloPascal(i-1, k-1) addi $a0, $s0, -1 # i-1 addi $a1, $s1, 0 # k jal TRIANGULO_PASCAL # Call to trianguloPascal(i-1, k) add $s3, $zero, $v0 # $s3 = trianguloPascal(i-1, k) add $v0, $s2, $s3 # return (trianguloPascal(i-1, k-1) + trianguloPascal(i-1, k)) END_IF_ELSE: END_TRIANGULO_PASCAL: # Load from stack lw $ra, 0($sp) lw $s0, 4($sp) lw $s1, 8($sp) lw $s2, 12($sp) lw $s3, 16($sp) addi $sp, $sp, 20 jr $ra # Return to $ra

freq=FALSE

hist output

否则,箱的高度将是样本数量的函数。实际上,曲线在技术上确实出现在你的图表上,它非常小,以至于你无法将它与y = 0的扁平线区分开来。